Custom UINavigationController UIToolbar subclass

2019-07-23 13:16发布

问题:

I need to work with a subclassed UIToolbar in the UINavigationController. I know this can be done via Interface Builder but I need it to be done programatically.

The docs state that the UINavigationController toolbar property is readonly so I'm at a bit of a loss as to how I proceed.

Related:

  • Custom UINavigationController UIToolbar Background Image

回答1:

A new init* method has been available since iOS 5

- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass 
                              toolbarClass:(Class)toolbarClass

Also don't forget

... you are responsible for adding a root view controller before presenting the navigation controller onscreen.