How to finally set the background color of UITabBar and the hue of UITabBar

I have been trying to set my UITabBar hue and background color for quite some time now, and nothing seems to work. While I tried:

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

and:

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

None of this seemed to affect my tab bar. I would also like to point out that I have a VC built into the navigation controller for which the global hue that I installed works fine.

+17
source share
3 answers

If you want to implicitly set the tint and barTint color tabs then in your Appdelegate.swift ,

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

If you want to set the tint and barTint color tabs for a specific viewController, then in ViewController.swift ,

  self.tabBarController?.tabBar.tintColor = .orange self.tabBarController?.tabBar.barTintColor = .green 
+38
source

Set the background color of the tab with barTintColor :

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

And for the hue color of the tab strip:

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

enter image description here

+15
source

Swift 4+ version

 UITabBar.appearance().barTintColor = UIColor.red UITabBar.appearance().tintColor = UIColor.white 
-2
source

All Articles