Mike_NotGuilty Mike_NotGuilty - 3 months ago 20
iOS Question

Swift - UINavigationController bar color does not change programmatically

I have a problem with changing the background color of my

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.
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.

Answer

You should set the navigation bar's barTintColor instead of backgroundColor. This should be what you are looking for.

Comments