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.
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
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()
Swift 4+ version
UITabBar.appearance().barTintColor = UIColor.red
UITabBar.appearance().tintColor = UIColor.white
来源:https://stackoverflow.com/questions/37626377/how-to-definitively-set-uitabbar-background-color-and-uitabbar-tint-color