简体   繁体   中英

How to change text color for tab bar button in storyboard ios8

I changed tab bar background in Bar Tint field and want to change text colour for tab bar button. By default is grey and blue. I try to change field Tint in section View, but it doesn't help.

NSDictionary *attribute = @{NSForegroundColorAttributeName:[UIColor redColor]};
[[UITabBarItem appearance] setTitleTextAttributes:attribute forState:UIControlStateNormal];

This will change the text colour for the tab bar button.

This is for selected state:

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

This is for not selected state:

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

Try it

To change tabbar text color you can use this

 [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary [UIColor redColor], UITextAttributeTextColor,[UIColor redColor],UITextAttributeTextShadowColor,[NSValue valueWithUIOffset:UIOffsetMake(0, 0.5)], UITextAttributeTextShadowOffset,[UIFont fontWithName:@"Arial" size:10], UITextAttributeFont,nil]forState:UIControlStateNormal];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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