iOS 颜色制作背景图片
2015-09-06 本文已影响276人
_浅墨_
// 设置 navigationBar 颜色
[self.navigationController.navigationBar setBackgroundImage:[UIImage saImageWithSingleColor:SATintColor] forBarMetrics:UIBarMetricsDefault];
+ (instancetype)saImageWithSingleColor:(UIColor *)color
{
UIGraphicsBeginImageContext(CGSizeMake(1.0f, 1.0f));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, 1, 1));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}