iOS4
在AppDelegate.m的文件中加入如下定义,覆盖NavigationBar的drawRect函数:
- @interface UINavigationBar (CustomBackgroud)
- - (void)drawRect:(CGRect)rect;
- @end
- @implementation UINavigationBar (CustomBackgroud)
- // iOS 4.* 下替换导航条皮肤
- - (void)drawRect:(CGRect)rect
- {
- UIImage *navBarImg = [[UIImage imageNamed:@"nav_bar"] stretchableImageWithLeftCapWidth:1 topCapHeight:0.0];
- [navBarImg drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- }
- @end
iOS5
[navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav.png"] forBarMetrics:UIBarMetricsDefault];