How to customize UINavigationBar with XIB?

本小妞迷上赌 提交于 2019-12-11 13:56:23

问题


UIViewController has a property called UINavigationItem.

So how can a UIViewController refer to UINavigationBar?

The UINavigationBar is not displayed yet till UIViewController is pushed into a UINavigationController. So it's not available in viewDidLoad.

So how do we customize it?

I added UINavigationBar to the XIB. However, how do I specify that I want to use THAT UINavigationBar rather than the one provided by UINavigationController?


回答1:


I added UINavigationBar to the XIB. However, how do I specify that I want to use THAT UINavigationBar rather than the one provided by UINavigationController?

You don't. The navigation bar is the nav controller's responsibility -- your view controller doesn't get to swap in its own nav bar. Each view controller has a navigation item that it can set to customize simple things like title and buttons, and you can get the navigation controller's nav bar when the view controller is pushed onto the navigation stack using the controller's navigationController property.



来源:https://stackoverflow.com/questions/18009394/how-to-customize-uinavigationbar-with-xib

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