John Doe John Doe - 11 months ago 72
Objective-C Question

Swift - Can't update UITabBar barTintColor


I've tried the following to update the background or "barTintColor" of my UITabBar. I can do this with objective-c by using
[[UITabBar appearance] setBarTintColor:[UIColor blackColor]];

What I've tried:

UITabBar.appearance().barTintColor = UIColor.white

self.navigationController?.navigationBar.barTintColor = UIColor.white;

UINavigationBar.appearance().barTintColor = UIColor.white

UINavigationBar.appearance().backgroundColor = UIColor.white

I'd like to avoid having some weird NSNotificationCenter solution and updating from AppDelegate. Why is this so difficult to achieve in Swift? Would appreciate any insight.

Joe Joe
Answer Source

Note: Below methods should work in Swift 3.Below code has to go inside your viewDidLoad to make it to work.

Method 1:

    tabBarController?.tabBar.barTintColor = UIColor.white
    tabBarController?.tabBar.tintColor =
    tabBarController?.tabBar.isTranslucent = false


enter image description here

Method 2:

Note: I am setting barTintColour to green to show both method works..

    UITabBar.appearance().barTintColor = // Its strange why this method didn't worked for you?.Try updating your post with viewDidLoad.Its a better way to understand the issue.
    UITabBar.appearance().tintColor = UIColor.purple


enter image description here