My current tab bar looks as follows:
My code is 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;
}
title of tab should be black as it is but only icon image should be black. 标题应为黑色,但仅图标图像应为黑色。 Expected tab should be like :
title of tab should be red as it is but only icon image should be red. 标题应为红色,但仅图标图像应为红色。 Expected tab should be like :
: make the whole tabBar color more transparent with same color : 使用相同的颜色使整个tabBar颜色更透明
Can anyone help to do this?
This accomplishes what you're asking for:
[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
[[UITabBar appearance] setAlpha:0.25];
在iOS8上的Swift中,它将是:
UITabBar.appearance().tintColor = UIColor.redColor()
The answers here aren't quite what I was looking for. It makes sense if you want a generic change to the color of all tab bar controllers in your app, but realistically, you don't necessarily want to make such a global change (not to mention that it can be difficult to debug and find later). It's better to be more focused, so you want to change the color directly.
As of iOS 8 , you need to change the tintColor
property of the tab bar. Hopefully, you're subclassing your UITabBarController
. If you are, you can set the color in viewDidLoad
:
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBar.tintColor = [UIColor grayColor];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.