Here's the code from the link @luvieere mentioned.
Paste this code into to the rootview controller just above
@implementation rootviewController
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"NavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
As of iOS 5, there is an official way to do this. (see iOS Developer Library)
// someplace where you create the UINavigationController
if ([navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
UIImage *image = [UIImage imageNamed:@"NavigationBar.png"];
[navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
But still, retain the old code for backward compatibility unless you really want to ditch iOS 4 and below.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…