How to subclass UINavigationBar for a UINavigationController programmatically?

后端 未结 6 454
半阙折子戏
半阙折子戏 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:22

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

    I faced one problem with the above method. There is a "initWithRootViewController" method to initialize UINavigationController. But, if I use "initWithNavigationBarClass" to init the UINavigationController, then there is no way I could set "rootViewController" for the UINavigationController.

    This link Changing a UINavigationController's rootViewController helped me to add a rootViewController after the UINavigationController is initialized with "initWithNavigationBarClass". Basically, the trick is to subclass UINavigationController. Though I haven't tested it in IB yet, but it is working fine in code.

提交回复
热议问题