change tabbar text color,iPhone

老子叫甜甜 提交于 2019-12-22 08:50:12

问题


I have created a tabbar programmatically.

Can we change color of title of the tabbar item? Default is white, and i m trying to make it black.

something like

 tabbaritem.text.textcolor=[UIcolor Blackcolor];

Thanks


回答1:


In iOS5 you use the appearance proxy to change the title color:

For a specific tabbar item:

[[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. If you want to change them all , I suggest you place the code on appdelegate didFinishLaunchingWithOptions:




回答2:


Just something else ...

To set your standard appearance in iOS 5:

In your AppDelegate.m do:

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

Saves you a lot of work.




回答3:


Maybe this updated code helps someone:

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

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


来源:https://stackoverflow.com/questions/11343894/change-tabbar-text-color-iphone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!