2016-11-17 57 views
1

我正在研究UITabBar应用程序。UITabBar所选项目色调

我想更改选定项目颜色与

[[UITabBar appearance] setTintColor:[UIColor redColor]] 

这工作,直到我想设置的TabBar的背景颜色与

[[UITabBar appearance] setBarTintColor:[UIColor blueColor]] 

那么酒吧是蓝色的,但高亮项目是灰色的。

[[UITabBar appearance] setBackgroundColor:[UIColor blueColor]] 

没有效果。 任何想法? 非常感谢!

+2

代替使用颜色,你可以尝试使用图像背景。 –

+0

谢谢 - 与另一个应用程序的图像背景。但我现在制作了两种颜色的图标:) – Steeve

回答

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"]]; 
+0

谢谢,这就是我现在所做的。我使用UIColor设置背景,但选择了和未选择的图标 – Steeve

2

试试这个代码

//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]; 

希望这有助于。