iOS 颜色制作背景图片

// 设置 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;
}

你可能感兴趣的:(iOS 颜色制作背景图片)