How can I make a UINavigationController's UINavigationBar invisible or at least change color

一个人想着一个人 提交于 2020-01-04 09:08:09

问题


I have a UINavigationController that is Linked to a ViewController that is set as RootController. I have enabled the UINavigationBar and put 3 UIViews each with a UIButton inside. Ideally I would like to make the UINavigationBar completely invisible, but I would also settle for setting the color to the background color of my ViewController. I am working in swift and I have tried things like

self.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.translucent = true

However nothing changes. Is there a correct way to do this?


回答1:


In swift, you can do:

self.navigationController?.setNavigationBarHidden(true, animated: true)

Please refer to Documentation for more details.




回答2:


I am also using Swift and was calling setNavigationBarHidden with no effect. I created a helper method in Obj-C that calls setNavigationBarHidden:animated: on a given navigation controller, and that works fine. So apparently this is just a bug, very frustrating.



来源:https://stackoverflow.com/questions/24519790/how-can-i-make-a-uinavigationcontrollers-uinavigationbar-invisible-or-at-least

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