How to change tabBar icon color in ios

My current tab bar looks like this:

enter image description here

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; } 

What I want to do:

Normal tab: the tab title should be black, since this is only the image of the image should be black. The expected tab should look like this:

enter image description here

Selected tab: the tab title should be red, since this is only the image of the image should be red. The expected tab should look like this:

enter image description here

tab bar color : make all tabBar color more transparent with the same color

Can anyone help with this?

+7
ios objective-c uitabbarcontroller uitabbar
source share
3 answers

Performs what you ask for:

 [[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]]; [[UITabBar appearance] setAlpha:0.25]; 
+21
source share

In Swift on iOS8, this will be:

 UITabBar.appearance().tintColor = UIColor.redColor() 
+4
source share

The answers here are not quite what I was looking for. It makes sense if you want the general color change of all the controllers of the tab bar in your application, but really, 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 is better to be more focused, so you want to directly change the color.

As in iOS 8 , you need to change the tintColor property in the tab bar. We hope you subclass your UITabBarController . If you are, you can set the color in viewDidLoad :

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

All Articles