我当前的标签栏如下所示:
我的代码如下:
-(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颜色更透明,颜色相同
任何人都可以帮忙吗?
答案 0 :(得分:22)
这可以满足您的要求:
[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
[[UITabBar appearance] setAlpha:0.25];
答案 1 :(得分:2)
这里的答案并不是我想要的。如果您想要对应用程序中所有标签栏控制器的颜色进行一般性更改,这是有道理的,但实际上,您不一定要进行这样的全局更改(更不用说以后调试和查找很难)。最好是更专注,所以你想直接改变颜色。
从 iOS 8 开始,您需要更改标签栏的tintColor
属性。希望你是你的UITabBarController
的子类。如果是,您可以在viewDidLoad
:
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBar.tintColor = [UIColor grayColor];
}