i have a tabbed application with 4 navControllers, which all should use the SAME UINavigationBar (same color, same buttons). now i only want to create the navbar once!
my first approach was to subclass UINavigationController, change the bar color and buttons, and use it for the navControllers in my AppDelegate, but the buttons didn’t show up and i found out that the documentation says that you’re not supposed to subclass UINavigationController…
can you help me out? i coulnd’t find a solution to this anywhere…
If you’re targeting iOS 5 only you may use the appearance proxy, which lets you customize UI elements at one point for the whole application.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html
If you need to do this on older iOS’ then there is no really nice solution to do this. There is an approach which uses method swizzling, described here.
http://samsoff.es/posts/customize-uikit-with-method-swizzling
But this does not work on iOS 5 anymore. Best approach is to use the appearance proxy for iOS 5 and a workaround like the method swizzling for older iOSes.
Edit:
Here’s some code I found to use the appearance proxy if it’s available and use method swizzling if it’s not.
The
drawRectCustomBackgroundmethod is implemented in a category onUINavigationBar.