我正在做一个uitabbar应用程序。
我想用
改变选中的项目颜色[[UITabBar appearance] setTintColor:[UIColor redColor]]
这是可行的,直到我想用
设置标签栏的背景色[[UITabBar appearance] setBarTintColor:[UIColor blueColor]]
则该栏为蓝色,但突出显示的项目是灰色的。
[[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"]];