ChenYilong / CYLTabBarController

[EN]It is an iOS UI module library for adding animation to iOS tabbar items and icons with Lottie, and adding a bigger center UITabBar Item. [CN]【中国特色 TabBar】一行代码实现 Lottie 动画TabBar,支持中间带+号的TabBar样式,自带红点角标,支持动态刷新。【iOS13 & Dark Mode & iPhone XS MAX supported】
MIT License
6.9k stars 1.45k forks source link

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

Open XinlinLiu opened 4 years ago

XinlinLiu commented 4 years ago



My issue:

zhuzhiwen0527 commented 4 years ago

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

Sunxb commented 4 years ago

同样遇到这个问题 ~

MayerFeng commented 4 years ago

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

zero-zql commented 4 years ago

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

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

即刻

itwyhuaing commented 4 years ago

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

LassZhang commented 4 years ago

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

itwyhuaing commented 4 years ago

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];

PZXforXcode commented 4 years ago

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

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

itwyhuaing commented 4 years ago

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

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

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

lyc59621 commented 4 years ago

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

lyc59621 commented 4 years ago

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)]]; }

参考这个,可以的

itwyhuaing commented 4 years ago

[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)一起调试下。

Lee0820 commented 4 years ago

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