简体   繁体   English

更改标签栏文字颜色,iPhone

[英]change tabbar text color,iPhone

I have created a tabbar programmatically. 我以编程方式创建了一个tabbar。

Can we change color of title of the tabbar item? 我们可以更改tabbar项目标题的颜色吗? Default is white, and im trying to make it black. 默认为白色,即时尝试将其设为黑色。

something like 就像是

 tabbaritem.text.textcolor=[UIcolor Blackcolor];

Thanks 谢谢

In iOS5 you use the appearance proxy to change the title color: 在iOS5中,您使用外观代理更改标题颜色:

For a specific tabbar item: 对于特定的tabbar项:

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

Or replace self.tabBarItem with [UITabBarItem appearance] to change all your tabbar items. 或者用[UITabBarItem appearance]替换self.tabBarItem以更改所有tabbar项。 If you want to change them all , I suggest you place the code on appdelegate didFinishLaunchingWithOptions: 如果你想改变它们,我建议你把代码放在appdelegate didFinishLaunchingWithOptions:

Just something else ... 别的......

To set your standard appearance in iOS 5: 要在iOS 5中设置标准外观:

In your AppDelegate.m do: 在你的AppDelegate.m中:

[[UITabBar appearance] setTintColor:myColor]; //or whatever you want to change

Saves you a lot of work. 为您节省大量的工作。

Maybe this updated code helps someone: 也许这个更新的代码帮助某人:

[UITabBarItem.appearance setTitleTextAttributes:@{
                                                  NSForegroundColorAttributeName : [UIColor lightGrayColor] } forState:UIControlStateNormal];

[UITabBarItem.appearance setTitleTextAttributes:@{
                                                  NSForegroundColorAttributeName : [UIColor whiteColor] }     forState:UIControlStateSelected];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM