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.
navigationController. navigationBar. barTintColor = UIColor. newBlueColor() and of course this just changes the colour of the navigation bar of the view controller that the code is within.
Here's a way of changing the color. You can also use images or css to use gradients. #nav { position: relative; left: -90px; background-color: #336699; // change #000088 (blue) for the color your want color: #FFFFFF; // change #FFFFFF (white) for the color you want. }
Go to the ViewController. swift file and add the ViewDidAppear method. a nav helper variable which saves typing. the Navigation Bar Style is set to black and the tint color is set to yellow, this will change the bar button items to yellow.
You should set the navigation bar's barTintColor
instead of backgroundColor
. This should be what you are looking for.
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.backgroundColor = UIColor.blue
This will solve it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With