一、如果只是设置选中状态的字体颜色,使用 tintColor 就可以达到效果
self.tabBar.tintColor = [UIColor redColor];二、但如果要将未选中状态和选中状态下的颜色都改变,可以使用 setTitleTextAttributes:<#(nullable NSDictionary<NSString *,id> *)#> forState:<#(UIControlState)#> 达到效果
[nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
[nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor]} forState:UIControlStateSelected];或者
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor]} forState:UIControlStateSelected];
本文介绍如何通过简单设置来改变 iOS 应用中 TabBar 的字体颜色,包括未选中状态和选中状态的颜色调整方法。适用于希望对 TabBar 外观进行自定义的 iOS 开发者。
370

被折叠的 条评论
为什么被折叠?



