我已经通过编程创建了一个选项卡栏。
我们能否更改选项卡项目标题的颜色? 默认是白色,我正在尝试将其改为黑色。
类似于:
我们能否更改选项卡项目标题的颜色? 默认是白色,我正在尝试将其改为黑色。
类似于:
tabbaritem.text.textcolor=[UIcolor Blackcolor];
谢谢
在 iOS5 中,您可以使用外观代理(appearance proxy)来更改标题颜色:
对于特定的选项卡条目:
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
[UIColor yellowColor], UITextAttributeTextColor,
[UIColor redColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
或者将self.tabBarItem
替换为[UITabBarItem appearance]
以更改所有选项卡栏项目。
如果您想要更改它们所有,我建议您将代码放置在应用程序委托的didFinishLaunchingWithOptions:
中。
UITabBarController
的项目中进行了测试,它确实可以工作。 - rckoenes只是另外一些东西...
在iOS 5中设置您的标准外观:
请在您的AppDelegate.m文件中执行以下操作:
[[UITabBar appearance] setTintColor:myColor]; //or whatever you want to change
可以省去很多工作。
也许这个更新的代码能帮助到某些人:
[UITabBarItem.appearance setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor lightGrayColor] } forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor whiteColor] } forState:UIControlStateSelected];
[UIcolor Blackcolor]
不是UIColor
的一个方法,我想你可能指的是[UIColor blackcolor]
。 - rckoenes