改变uitabbaritem的文字颜色

yog*_*dra 20 iphone

任何人都可以帮我解决这个奇怪的问题,无论如何都要将uitabbar项目的文本颜色从默认灰色更改为白色,将所选颜色更改为蓝色.

ban*_*isa 75

老问题,但我有一个新的答案,在iOS 5以后支持(我也使用LLVM 4.0文字)

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
                                         forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blueColor] }
                                         forState:UIControlStateSelected];
Run Code Online (Sandbox Code Playgroud)

  • 这是我使用和最喜欢的解决方案; 但是,不推荐使用UITextAttributeTextColor,因此只需将其替换为NSForegroundColorAttributeName,代码应该无错编译. (2认同)

Eik*_*ike 11

UITextAttributeTextColor从iOS版7.使用过时NSForegroundColorAttributeName代替.

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }
                                             forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

在斯威夫特

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.blackColor()], forState: .Normal)
Run Code Online (Sandbox Code Playgroud)


Sar*_*den 5

从 iOS 10 开始,可以unselectedItemTintColorUITabBar.

tintColor的颜色大于UITabBar所选项目的颜色。

如果您想为任何项目设置唯一值,您还可以直接与和tabBarItem.titleTextAttributes(for:)组合在该项目上设置(前面提到的)。tabBarItem.imagetabBarItem.selectedImage


luv*_*ere 0

查看此问题此问题的答案,但请注意,您的应用程序可能会因修改此类默认选项卡栏组件而被拒绝。