Search code examples
iosobjective-cuinavigationcontrollersubclassuitoolbar

Custom UINavigationController UIToolbar subclass


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:


Solution

  • 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.