How to definitively set UITabBar background color and UITabBar tint color

非 Y 不嫁゛ 提交于 2019-12-12 07:41: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.


回答1:


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



回答2:


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()




回答3:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!