[英]Swift - UINavigationController bar color does not change programmatically
I have a problem with changing the background color of my UINavigationBar
. 我在更改
UINavigationBar
的背景颜色时遇到问题。 Here's what I tried so far: 这是我到目前为止所尝试的:
self.navigationController?.navigationBar.translucent = true
self.navigationController?.navigationBar.backgroundColor = UIColor.blueColor()
The navigation bar does not change. 导航栏不会更改。 Even setting the translucency to true has no effect at all.
即使将半透明度设置为true也完全没有效果。 I can change the tint color without any problems, but not the background color.
我可以毫无问题地改变色调颜色,但不能改变背景颜色。
But if I change the color in the storyboard, it works fine! 但如果我改变故事板中的颜色,它就可以正常工作!
Is there an option in the storyboard that I enabled/disabled by mistake? 故事板中是否有错误启用/禁用的选项? Can someone help me with this?
有人可以帮我弄这个吗? Thanks.
谢谢。
You should set the navigation bar's barTintColor
instead of backgroundColor
. 您应该设置导航栏的
barTintColor
而不是backgroundColor
。 This should be what you are looking for. 这应该是你正在寻找的。
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.backgroundColor = UIColor.blue
This will solve it. 这将解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.