Reputation: 2169
I have a UIView with UINavigationBar.
I'm building this code to setting background color at View and also at NavigationBar.
So this is the code:
override func viewDidLoad(){
super.viewDidLoad()
self.navigationController?.navigationBar.barTintColor = getColor(red: 41, green: 151, blue: 255)
self.view.backgroundColor = getColor(red: 41, green: 151, blue: 255)
}
func getColor(red: Int, green: Int, blue: Int) ->
UIColor{
return UIColor(red: CGFloat(Float(red) / 255.0),
green CGFloat(Float(red) / 255.0),
blue: CGFloat(Float(red) / 255.0),
alpha: CGFloat(1.0))
}
As you can see the color is the same, but the output view is like this:
As you can see, the NavBar have the different color and I don't know why.
Upvotes: 1
Views: 813
Reputation: 185
try this
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = UIColor.clear
instead of
self.navigationController?.navigationBar.barTintColor = getColor(red: 41, green: 151, blue: 255)
Upvotes: 2
Reputation: 234
Apparently, this is because of navigation bar isTranslucent
, set it programmatically to false
or if you're using storyboard it could be done by removing the check from Translucent like the photo attached.
Upvotes: 0
Reputation: 2776
It is probably because your navigation bar is translucent, try settings isTranslucent
to false.
Upvotes: 0
Reputation: 368
I think you will need to set the navigation bar's isTranslucent
property to false
.
Upvotes: 0