How to definitiveley set UITabBar background color

2019-04-04 21:05发布

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.

3条回答
甜甜的少女心
2楼-- · 2019-04-04 21:10

Swift 4+ version

UITabBar.appearance().barTintColor = UIColor.red
UITabBar.appearance().tintColor = UIColor.white
查看更多
迷人小祖宗
3楼-- · 2019-04-04 21:17

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

查看更多
放荡不羁爱自由
4楼-- · 2019-04-04 21:18

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

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

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

 self.tabBarController?.tabBar.tintColor = UIColor.orangeColor()
 self.tabBarController?.tabBar.barTintColor = UIColor.greenColor()
查看更多
登录 后发表回答