如何在ios中更改tabBar图标颜色 [英] how to change tabBar icon color in ios

查看:114
本文介绍了如何在ios中更改tabBar图标颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My current tab bar looks as follows:

我的代码如下:

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

这篇关于如何在ios中更改tabBar图标颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆