iOS 顏色製作背景圖片

躍然發表於2015-09-06
// 設定 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;
}

相關文章