- (void)viewDidLoad
{
[super viewDidLoad];
[self.navBar setTintColor:[UIColor redColor]];
UIImage *backgroundImage = [self imageWithColor:[UIColor redColor]];
[self.navBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}
//绘制一张纯色的图片
-(UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
文章转载自http://www.aslibra.com/blog/read.php/1758.htm