[英]how to change tabBar icon color in ios
我当前的标签栏如下所示:
我的代码如下:
-(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;
}
我想做的是:
普通标签:标签 预期标签应为:
选定的标签:标签 预期标签应为:
标签栏颜色 :
有人可以帮忙吗?
这可以满足您的要求:
[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
[[UITabBar appearance] setAlpha:0.25];
在iOS8上的Swift中,它将是:
UITabBar.appearance().tintColor = UIColor.redColor()
这里的答案并不完全是我想要的。 如果您想对应用程序中所有选项卡栏控制器的颜色进行通用更改,这是有道理的,但实际上,您不一定要进行这样的全局更改(更不用说以后很难调试和查找) )。 最好集中注意力,以便您直接更改颜色。
从iOS 8开始 ,您需要更改选项卡栏的tintColor
属性。 希望您正在将UITabBarController
子类化。 如果是这样,可以在viewDidLoad
设置颜色:
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBar.tintColor = [UIColor grayColor];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.