Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to definitively set UITabBar background color and tint color

I have been trying to set my UITabBar's tint color and background color for quite some time now and nothing seems to work. So far I have tried:

tabBarController?.tabBar.backgroundColor = UIColor.orangeColor()
tabBarController?.tabBar.barTintColor = UIColor.whiteColor()

as well as:

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

Neither of these seemed to have any effect on my tab bar. I'd also like to mention that I have the VC embedded in a navigation controller for which the global tint color that I set works perfectly fine.

like image 289
Harry Merzin Avatar asked Jun 04 '16 04:06

Harry Merzin


3 Answers

Set tab bar background color with barTintColor:

self.tabBar.barTintColor = UIColor.blueColor() //or UITabBar.appearance().barTintColor = UIColor.blueColor() 

And for tab bar tint color:

self.tabBar.tintColor = UIColor.whiteColor() // Selected tab color //or UITabBar.appearance().tintColor = UIColor.whiteColor() 

enter image description here

like image 27
Pushpa Y Avatar answered Sep 23 '22 14:09

Pushpa Y


If you want to set tabbar's tint and barTint color implicitly then in your Appdelegate.swift,

    UITabBar.appearance().barTintColor = .orange     UITabBar.appearance().tintColor = .green 

If you want to set tabbar's tint and barTint color for specific viewController then in ViewController.swift,

 self.tabBarController?.tabBar.tintColor = .orange  self.tabBarController?.tabBar.barTintColor = .green 
like image 77
Ketan Parmar Avatar answered Sep 21 '22 14:09

Ketan Parmar


In similar fashion to how UINavigationBar is by default transparent on iOS 15 when there is no content behind it, the UITabBar works the same way. This might either be a nice visual refresh you get for free (since it is turned on by default once you build with Xcode 13) or it might cause a lot of issues for your app.

if #available(iOS 13.0, *) { 
    let tabBarAppearance: UITabBarAppearance = UITabBarAppearance() 
    tabBarAppearance.configureWithDefaultBackground() 
    tabBarAppearance.backgroundColor = UIColor.tabBarBackground 
    UITabBar.appearance().standardAppearance = tabBarAppearance 
}
if #available(iOS 15.0, *) { 
    UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance 
} 
like image 23
Carlos Cardona Avatar answered Sep 25 '22 14:09

Carlos Cardona