ios 更改标签栏的背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36862564/
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
Changing the background color of Tab Bar
提问by MrDank
I am trying to get desired color rendered in the background of Tab Bar however I am facing problems. These are the things that I tried :-
我正在尝试在 Tab Bar 的背景中呈现所需的颜色,但是我遇到了问题。这些是我尝试过的事情:-
Changing the background color of tab bar object from storyboard. The color rendered is always lighter than the desired color.
Programmatically changing the color of the tab bar using the following code inside
viewDidLoad()
methodself.tabBar.translucent = false self.tabBar.backgroundColor = UIColor(hexString: "323B61")
It doesn't change the color. Instead , the color rendered is white.
从故事板更改标签栏对象的背景颜色。渲染的颜色总是比所需的颜色浅。
使用以下代码内
viewDidLoad()
方法以编程方式更改选项卡栏的颜色self.tabBar.translucent = false self.tabBar.backgroundColor = UIColor(hexString: "323B61")
它不会改变颜色。相反,呈现的颜色是白色。
How can I get the desired color for Tab Bar?
如何获得 Tab Bar 所需的颜色?
回答by Abhinandan Pratap
To change background colour of UITabBar
更改 UITabBar 的背景颜色
TabBarController* Tcontroller =(TabBarController*)self.window.rootViewController;
Tcontroller.tabBar.barTintColor=[UIColor yourcolour];
Swift 3
斯威夫特 3
Based on the code above, you can get it by doing this
根据上面的代码,你可以通过这样做得到它
let Tcontroller = self.window.rootViewController as? UITabBarController
Tcontroller?.tabBar.barTintColor = UIColor.black // your color
or in more general
或者更一般地说
UITabBar.appearance().barTintColor = UIColor.black // your color
回答by Anurag Sharma
回答by Trevor
swift 4
迅捷 4
Inside your UITabBarController
在你的 UITabBarController 里面
tabBar.barTintColor = .purple
tabBar.isTranslucent = false
You also have access to:
您还可以访问:
tabBar.tintColor = .green
tabBar.unselectedItemTintColor = .blue
to change icon colours if you want.
如果需要,可以更改图标颜色。
回答by Madhumitha
try this code
试试这个代码
self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0.376 green:0.729 blue:0.318 alpha:1.000];