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.
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)
我认为您需要将导航栏的isTranslucent
属性设置为false
。
可能是因为你的导航栏是半透明的,试试把isTranslucent
设置为false。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.