我正在使用UITabBar-Application。
我想用
更改所选的项目颜色[[UITabBar appearance] setTintColor:[UIColor redColor]]
这有效,直到我想用
设置TabBar的背景颜色[[UITabBar appearance] setBarTintColor:[UIColor blueColor]]
然后条形图为蓝色,但突出显示的项目为灰色。
[[UITabBar appearance] setBackgroundColor:[UIColor blueColor]]
无效。 任何的想法? 非常感谢你!
答案 0 :(得分:3)
试用此代码
//Set greenColor for normal State
[UITabBarItem.appearance setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal];
//Set purpleColor for normal State
[UITabBarItem.appearance setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor purpleColor] } forState:UIControlStateSelected];
希望这有帮助。
答案 1 :(得分:0)
您发布的代码似乎正在运行。你也可以用图像来做。试试这个:
[tabBarItem1 setImage:[[UIImage imageNamed:@"home.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"home_selected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];