如何在 iOS 7 中更改 tabBarItems 的文本和图标颜色? [英] How can I change the text and icon colors for tabBarItems in iOS 7?
本文介绍了如何在 iOS 7 中更改 tabBarItems 的文本和图标颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 iOS 7 中更改 UITabBar 和 UITabBarItems 的文本和图标颜色?对于未选择的标签栏项目,默认的灰色文本显得暗淡且难以阅读.
How can I change the text and icon colors for UITabBar and UITabBarItems in iOS 7? The default gray text seems dim and hard to read for unselected tabbar items.
推荐答案
为此您需要做两件事:
1) 如果要自定义 TabBar 本身,则需要为 tabBarController 设置 barTintColor:
1) If you want to customize the TabBar itself, you need to set the barTintColor for the tabBarController:
// this will generate a black tab bar
tabBarController.tabBar.barTintColor = [UIColor blackColor];
// this will give selected icons and text your apps tint color
tabBarController.tabBar.tintColor = appTintColor; // appTintColor is a UIColor *
2) 为每个要覆盖的状态设置 tabBarItem 文本外观:
2) Set the tabBarItem text appearance for each state that you want to override:
[[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];
这篇关于如何在 iOS 7 中更改 tabBarItems 的文本和图标颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文