简体   繁体   English

如何在Storyboard iOS8中更改标签栏按钮的文本颜色

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

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

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