CYLTabBarController icon indicating copy to clipboard operation
CYLTabBarController copied to clipboard

iOS13 通过 该方法设置tabbar字体颜色不起作用[[UITabBarItem appearance] setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];

Open XinlinLiu opened this issue 5 years ago • 13 comments



My issue:

XinlinLiu avatar Sep 17 '19 03:09 XinlinLiu

iOS 13 tabbar添加了一个新属性 UITabBarAppearance 可以在这里设置

zhuzhiwen0527 avatar Sep 23 '19 10:09 zhuzhiwen0527

同样遇到这个问题 ~

Sunxb avatar Sep 24 '19 05:09 Sunxb

[[UITabBar appearance] setUnselectedItemTintColor:RGBACOLOR(51, 51, 51, 1)];

MayerFeng avatar Sep 24 '19 08:09 MayerFeng

在 - (void)customizeTabBarAppearance:(CYLTabBarController *)tabBarController 方法内添加

[[UITabBar appearance] setUnselectedItemTintColor:[UIColor redColor]];

即刻

zero-zql avatar Sep 25 '19 01:09 zero-zql

请问设置字体该用什么属性呢

itwyhuaing avatar Sep 25 '19 08:09 itwyhuaing

iOS 刚进去时,各TabbarItem 文字颜色是正常的。从A页面Push 到B ,再返回,Title 颜色就会变成蓝色或者红色。 请问,在哪里设置??

LassZhang avatar Sep 27 '19 06:09 LassZhang

iOS 刚进去时,各TabbarItem 文字颜色是正常的。从A页面Push 到B ,再返回,Title 颜色就会变成蓝色或者红色。 请问,在哪里设置??

iOS 13 之前是 [tabBarItem setTitleTextAttributes:attributDicNor forState:UIControlStateNormal]; [tabBarItem setTitleTextAttributes:attributDicSelect forState:UIControlStateSelected];

现在设置 UITabBar *tabBar = [UITabBar appearance]; [tabBar setTintColor:selectColor]; [tabBar setUnselectedItemTintColor:unSelectColor];

itwyhuaing avatar Sep 27 '19 07:09 itwyhuaing

请问设置字体该用什么属性呢

兄弟知道字体设置的属性了吗

PZXforXcode avatar Oct 09 '19 07:10 PZXforXcode

请问设置字体该用什么属性呢

兄弟知道字体设置的属性了吗

iOS 13 之后 字体颜色设置用的是 UITabBar *tabBar = [UITabBar appearance]; [tabBar setTintColor:selectColor]; [tabBar setUnselectedItemTintColor:unSelectColor];

itwyhuaing avatar Oct 09 '19 10:10 itwyhuaing

[tabBar setTintColor:selectColor]; 这句代码设置选中颜色不生效啊 设置字体呢,怎么设置

lyc59621 avatar Oct 12 '19 06:10 lyc59621

if (@available(iOS 13.0, *)) { UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init]; UITabBarItemAppearance *inlineLayoutAppearance = [[UITabBarItemAppearance alloc] init]; [ inlineLayoutAppearance.normal setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:RGB(169, 181, 208)}]; [ inlineLayoutAppearance.selected setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:CclearBlue(1)}]; standardAppearance.stackedLayoutAppearance = inlineLayoutAppearance; standardAppearance.backgroundColor = [UIColor whiteColor]; standardAppearance.shadowImage = [UIImage imageWithColor:CpaleGrey(1)]; self.tabBar.standardAppearance = standardAppearance; } else { // Override point for customization after application launch. [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:RGB(169, 181, 208)} forState:UIControlStateNormal]; // 选中状态的标题颜色 [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:CclearBlue(1)} forState:UIControlStateSelected]; [[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]]; [[UITabBar appearance] setShadowImage:[UIImage imageWithColor:CpaleGrey(1)]]; }

参考这个,可以的

lyc59621 avatar Oct 12 '19 07:10 lyc59621

[tabBar setTintColor:selectColor]; 这句代码设置选中颜色不生效啊 设置字体呢,怎么设置

反复又看了下原来的代码以及 iOS 的 API ,有问题的是 iOS 10及其之后推出一个 setUnselectedItemTintColor ;其他并没改动。 关于字体颜色设置不生效问题, “[tabBar setTintColor:selectColor];”这行代码的优先级并不是最高的,代码中倘若设置了 “[attributDicSelect setValue:selectColor forKey:NSForegroundColorAttributeName];[tabBarItem setTitleTextAttributes:attributDicSelect forState:UIControlStateSelected];”这样的代码,"setTintColor" 这行代码的确不会生效。不知兄台代码逻辑是否这样?! 调整之后的颜色设置代码: “ NSMutableDictionary *attributDicNor = [NSMutableDictionary dictionary]; NSMutableDictionary *attributDicSelect = [NSMutableDictionary dictionary]; UITabBar *tabBar = [UITabBar appearance]; if (@available(iOS 10.0, *)) { [tabBar setUnselectedItemTintColor:unSelectColor]; } else { [attributDicNor setValue:unSelectColor forKey:NSForegroundColorAttributeName]; } [attributDicSelect setValue:selectColor forKey:NSForegroundColorAttributeName]; UITabBarItem *tabBarItem = [UITabBarItem appearance]; [tabBarItem setTitleTextAttributes:attributDicNor forState:UIControlStateNormal]; [tabBarItem setTitleTextAttributes:attributDicSelect forState:UIControlStateSelected]; ”

关于字体大小设置: “ UIFont *unSelectFont = [UIFont systemFontOfSize:10]; NSMutableDictionary *attributDicNor = [NSMutableDictionary dictionary]; [attributDicNor setValue:unSelectFont forKey:NSFontAttributeName]; UITabBarItem *tabBarItem = [UITabBarItem appearance]; [tabBarItem setTitleTextAttributes:attributDicNor forState:UIControlStateNormal]; ”

代码都是测试过的,测试设备:iPhone 6 iOS9.2、iPhone XR iOS12.1、iPhone XS iOS 13.0。 兄台不介意可以代码发到163邮箱(itwyhuaing)一起调试下。

itwyhuaing avatar Oct 14 '19 07:10 itwyhuaing

@lyc59621 我是这么写的之前,但是这样的话 CYLTabBarItemTitlePositionAdjustment 的设置就会失效,感觉像是被重置了,目前没找到办法

Lee0820 avatar Jan 14 '20 08:01 Lee0820