How to remove navigation bar colour clear in swift

2019-08-16 18:29发布

I want to clear color of navigation bar. In my ViewController there is a background image on that, when i remove color of navigation barTintColor, navigationController.view.background and navigation background image then simulator shows me :- enter image description here

I have been trying alots of codes but there is no solution found. I want navigation Bar like that:- enter image description here

with clear navigation bar color. Is there any solution, let me know? Thanks!

2条回答
别忘想泡老子
2楼-- · 2019-08-16 19:02

Better you must avoid the navigation bar. Hide the navigation bar in the navigation controller and user custom view in your view controller to avoid this issue.

查看更多
Juvenile、少年°
3楼-- · 2019-08-16 19:25

You can make the navigation bar transparent in viewWillAppear and remove transparency in viewWillDisappear as follows

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.isTranslucent = true
}
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
    self.navigationController?.navigationBar.shadowImage = nil
    self.navigationController?.navigationBar.isTranslucent = false
}

The background image and the back button will be visible

enter image description here

查看更多
登录 后发表回答