【发布时间】:2015-02-20 21:24:32
【问题描述】:
我已经在应用委托中设置了标签栏的颜色:
[[UITabBar appearance] setTintColor:[UIColor redColor]];
效果很好,但我还需要单独设置文本颜色。我希望我的图像带有红色,但文字必须是白色。
这有可能吗?
【问题讨论】:
标签: ios ios7 ios8 uitabbarcontroller
我已经在应用委托中设置了标签栏的颜色:
[[UITabBar appearance] setTintColor:[UIColor redColor]];
效果很好,但我还需要单独设置文本颜色。我希望我的图像带有红色,但文字必须是白色。
这有可能吗?
【问题讨论】:
标签: ios ios7 ios8 uitabbarcontroller
改变uitabbaritem的颜色使用setTitleTextAttributes希望这段代码对你有帮助:
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [[uicolor whitecolor] }
forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
forState:UIControlStateNormal];
改变图像色调:
[[UITabBar appearance] setTintColor:[UIColor redcolor]];
【讨论】:
https://stackoverflow.com/a/18734795/860343 的答案涵盖了您可能需要对标签栏项目进行的大部分编辑。
简而言之,代码如下:
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : appTintColor
} forState:UIControlStateSelected];
// doing this results in an easier to read unselected state then the default iOS 7 one
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
【讨论】: