如何更改ios中的tabBar图标颜色

我目前的标签栏如下所示:

在这里输入图像说明

我的代码如下:

-(void)startTabBar{ self.tabBarController = [[UITabBarController alloc] init]; TAB_1 *tab_1 = [[TAB_1 alloc]init]; TAB_2 *tab_2 = [[TAB_2 alloc]init]; TAB_3 *tab_3 = [[TAB_3 alloc]init]; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal]; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName,nil] forState:UIControlStateSelected]; NSArray* controllers = [NSArray arrayWithObjects:tab_1,tab_2, tab_3, nil]; self.tabBarController.viewControllers = controllers; self.window.rootViewController = self.tabBarController; } 

我想要做的是:

标准标签:标签的 标题应该是黑色的,但只有图标图像应该是黑色的。 期望的标签应该是这样的:

在这里输入图像说明

所选标签:标签的 标题应该是红色,但只有图标图像应该是红色的。 期望的标签应该是这样的:

在这里输入图像说明

标签栏颜色使整个tabBar颜色更透明,颜色相同

任何人都可以帮助做到这一点?

这完成了你所要求的:

 [[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]]; [[UITabBar appearance] setAlpha:0.25]; 

在iOS8的Swift中,它将是:

 UITabBar.appearance().tintColor = UIColor.redColor() 

这里的答案不是我正在寻找的。 如果您希望对应用程序中的所有标签栏控制器的颜色进行通用更改,那么这样做是有道理的,但实际上,您并不一定希望进行全局更改(更不用说可能很难debugging并稍后查找)。 最好是更专注,所以你想直接改变颜色。

iOS 8开始 ,您需要更改标签栏的tintColor属性。 希望你能inheritance你的UITabBarController 。 如果你是,你可以在viewDidLoad设置颜色:

 - (void)viewDidLoad { [super viewDidLoad]; self.tabBar.tintColor = [UIColor grayColor]; }