如果在iOS13中使用以下代碼設置Tabbar文字渲染在點擊其他item切換或則push返回的時候是會失效的,字體顏色是會返回系統(tǒng)默認的藍色
UITabBarItem *item = [UITabBarItem appearance];
[item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
[item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
iOS13后文檔中對#UIBbarAppearance#對象有說明,在設置的對象屬性時需要初始化并設置一個UIBarAppearance或則子類來設置其對象屬性
正確設置方式:
if (@available(iOS 13.0, *)) {
// titColor就是選中的顏色
self.tabBar.tintColor = [UIColor redColor];
//如果需要設置默認顏色可以使用setUnselectedItemTintColor來設置未選中顏色
[self.tabBar setUnselectedItemTintColor:UIColor redColor];
} else {
// 統(tǒng)一給所有的UITabBarItem設置文字屬性
UITabBarItem *item = [UITabBarItem appearance];
[item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
[item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}
二唁奢、去除上面的線
if (@available(iOS 13.0,*)) {
UITabBarAppearance * appeearance = self.standardAppearance;
appeearance.backgroundImage = [UIImage imageWithColor:[UIColor clearColor]];;
appeearance.shadowImage = [UIImage imageWithColor:[UIColor clearColor]];;
self.standardAppearance = appeearance;
}
else{
self.backgroundImage = [UIImage new];
self.shadowImage = [UIImage new];
}
//imageWithColor是為UIImage寫的一個分類方法:根據顏色生成一張圖片弧呐,其中 [UIImage new] 方法已不在適用铅碍。