How to subclass UINavigationBar for a UINavigationController programmatically?

后端 未结 6 450
半阙折子戏
半阙折子戏 2020-11-29 20:00

I\'m using a custom drawRect function to draw on UINavigationBar across my application in iOS4, it doesn\'t use images, only CoreGraphics.

Since you ca

6条回答
  •  春和景丽
    2020-11-29 20:20

    As of iOS6, this is now quite simple to accomplish without swizzling or messing with other classes by using UINavigationControllers method initWithNavigationBarClass:toolbarClass:

    - (id)initWithNavigationBarClass:(Class)navigationBarClass 
                        toolbarClass:(Class)toolbarClass;
    

    From the docs:

    Initializes and returns a newly created navigation controller that uses your custom bar subclasses.

    Answer updated for iOS6.

提交回复
热议问题