UITabBar tintColor not changed.

I set the global tintColor and I see it in the interface builder when I select UITabBar as well as UITabBarController, still when I launch the application, the hue of the selected UITabBarItem is the default value for iOS (blue) and not what I set . What am I missing?

PS UITabBarController is redirected to navigationController, it is not rootViewController

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

Use this code in the didFinishLaunchingWithOptions: method of your appDelegate

  [[UITabBar appearance] setSelectedImageTintColor: [UIColor redColor]]; 

Replace the red color with the color you want.

+10
source share

The storyboard does not yet support this. But you can set a custom runtime attribute in the storyboard.

Select the tab bar of the tab bar controller. Select the tab bar of the tab bar controller.

Select an identity inspector. (A view in which you can set the view class.)

Select Identity Inspector

And if you want to change the hue color of the selected color , use instead.

+12
source share

If you focus on iOS 8, then

selectedImageTintColor deprecated in iOS 8 use tintColor

Swift

  UITabBar.appearance().tintColor = UIColor.redColor() 

Goal c

  [[UITabBar appearance] setTintColor: [UIColor redColor]]; 
+4
source share

In my application, I wanted each ViewController to have a unique TabBarItem color when it was presented.

enter image description here

In iOS 8, manually adding the tintColor attribute to the storyboard worked fine, but it no longer has any effect in iOS 9 / Xcode 8.

I solved the problem by including the following code in each of my ViewControllers of my TabBarController type, overriding each of my ViewDidAppear () functions.

 override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) self.tabBarController?.tabBar.tintColor = UIColor.whateverColor //The rest of your code } 

Is it safe in any ViewController because of? after calling tabBarController. If the ViewController is not embedded in the TabBarController, the entire row is simply ignored.

By putting this code in each of your VCs, you can easily specify the color of each TabBarItem element.

0
source share

All Articles