How to customize UINavigationBar with XIB?

2019-08-07 17:38发布

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条回答
Bombasti
2楼-- · 2019-08-07 18:22

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.

查看更多
登录 后发表回答