This is along the same line as Simone's answer, but works for iOS 5 and iOS < 5. This is what I'm using in app. You need to call [UINavigationBar setupIos5PlusNavBarImage]
somewhere in your app initialization (applicationDidFinishLaunching: is a good candidate). On iOS 5+, setupIos5PlusNavBarImage will use the new UIAppearance protocol to set the background and the drawRect override will be ignored. On iOS < 5, setupIos5PlusNavBarImage will basically be a no-op and the drawRect will handle drawing the image.
Interface:
@interface UINavigationBar (CustomNavigationBar)
+ (void) setupIos5PlusNavBarImage;
- (void) drawRect: (CGRect) rect;
@end
Implementation:
@implementation UINavigationBar (CustomNavigationBar)
+ (void) setupIos5PlusNavBarImage
{
if ([UINavigationBar respondsToSelector: @selector(appearance)])
{
[[UINavigationBar appearance] setBackgroundImage: [UIImage imageNamed: @"menuBar.png"] forBarMetrics: UIBarMetricsDefault];
}
}
- (void) drawRect: (CGRect) rect
{
UIImage* img = [UIImage imageNamed: @"menuBar.png"];
[img drawInRect: CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end