The navigation bar is often used during ios ui development. The default style is relatively simple, so you often need to modify the style of the navigation bar.
Ios4:
- (void)drawRect:(CGRect)rect { UIImage *image = [UIImage imageNamed:@"navbar_bg.png"]; [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; return;}
After ios5:
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{ [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg.png"] forBarMetrics:UIBarMetricsDefault];}
Ios7, because the navigation bar will be extended to the system status bar, so the Image Height needs to be increased by 20 PX. If there is no additional processing, a black bar in the status bar may appear.
if (7.0 <= [[[UIDevice currentDevice] systemVersion] floatValue]) { [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg_7.png"] forBarMetrics:UIBarMetricsDefault]; } else { [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg.png"] forBarMetrics:UIBarMetricsDefault]; }