September 17, 2012

Setting custom background for UINavigationBar to support iOS6, iOS5 and iOS4

Until iOS5 came out we used drawRect in AppDelegate in order to overwrite the UINavigationBar with our custom draw. Now that iOS5 and iOS6 is out, there is a new method for styling, one that older versions of iOS do not support.

In order to support a custom UINavigationBar styling for iOS4 and older we need to implement in our project both methods, and here is how we do it.

In AppDelegate use this code (in the header between #import and @implementation AppDelegate):

In viewDidLoad use this code for iOS5 and iOS6:

That’s it!

Posted By