UITabBar 所选项目色调颜色

UITabBar Selected Item Tint Color

我正在开发 UITabBar 应用程序。

我想用

更改所选项目的颜色
[[UITabBar appearance] setTintColor:[UIColor redColor]]

这行得通,直到我想用

设置 TabBar 的背景颜色
[[UITabBar appearance] setBarTintColor:[UIColor blueColor]]

那么Bar是蓝色的,但是突出显示的Items是灰色的。

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

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

试试这个代码

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

希望对您有所帮助。

您发布的代码似乎可以正常工作。你也可以用图像来做。试试这个:

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