创建纯色的navigationbar
2016-05-19 本文已影响19人
lixiaoshuai
问题如题
代码如下
UIImage * image = [UIImage imageWithColor:[UIColor GreenColor]];
[self.navigationController.navigationBar setBackImage:image forBarMetrics:UIBarMetricsDefault];
- (UIImage*)imageWithColor:(UIColor*)color{
CGRect rect = CGRectMake(0,0,1,1);
UIGraghicsBeginImageContext(rect.size);
CGContextRef content = UIGraphicsGetCurrentContext();
CGContentSetColorWithColor(context,[color CGColor]);
CGContentFillRect(context,rect);
UIImage * image = UIGraphicsGetImageFromCurrentImageContext;
UIGraphicsEndImageContext();
Return image;
}