Customizable background settings for UINavigationBar to support iOS5 and iOS4 too!
As you know, before iOS 5, we used drawRect overrides in AppDelegate to configure the UINavigationBar . But you know, iOS 5 gives us a new styling method (and the old one doesn't work).
How to create an application that will work on iOS 4 and iOS 5 with a stylized UINavigationBar ?
You must do both!
In AppDelegate use this code:
@implementation UINavigationBar (UINavigationBarCategory) - (void)drawRect:(CGRect)rect { UIImage *img = [UIImage imageNamed:@"navbar.png"]; [img drawInRect:rect]; } @end
and in viewDidLoad for iOS5 (in your implementation):
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){ [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault]; }
If you see, here we ask if navbar will respond to the selection in order to avoid a crash on iOS4!
source share