iOS颜色转图片

- (UIImage *)imageWithColor:(UIColor *)color

{
    CGRect rect = CGRectMake(0.0f, 0.0f, 80.0f, 45.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

你可能感兴趣的:(iOS颜色转图片)