ios 如何明确设置 UITabBar 背景颜色和色调颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37626377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to definitively set UITabBar background color and tint color
提问by Harry Merzin
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:
UITabBar
一段时间以来,我一直在尝试设置我的色调和背景色,但似乎没有任何效果。到目前为止,我已经尝试过:
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.
这些似乎都对我的标签栏没有任何影响。我还想提一下,我将 VC 嵌入到导航控制器中,我为其设置的全局色调颜色非常好。
回答by Ketan Parmar
If you want to set tabbar's tint and barTint color
implicitly then in your Appdelegate.swift
,
如果您想tint and barTint color
隐式设置标签栏,则在您的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
,
如果你想tint and barTint color
为特定的 viewController设置标签栏,然后在ViewController.swift
,
self.tabBarController?.tabBar.tintColor = .orange
self.tabBarController?.tabBar.barTintColor = .green
回答by Pushpa Y
Set tab bar background color with barTintColor:
使用 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()
回答by Abhishek Jain
Swift 4+ version
斯威夫特 4+ 版本
UITabBar.appearance().barTintColor = UIColor.red
UITabBar.appearance().tintColor = UIColor.white