How to remove navigation bar colour clear in swift4?

可紊 提交于 2019-12-13 04:28:42

问题


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

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

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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/55627473/how-to-remove-navigation-bar-colour-clear-in-swift4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!