美文网首页
用颜色UIColor生成图片UIImage

用颜色UIColor生成图片UIImage

作者: amberling | 来源:发表于2017-02-14 15:39 被阅读1055次
+(UIImage*)imageFromColor:(UIColor*)color size:(CGSize)size
{
    CGRect rect=CGRectMake(0.0f, 0.0f, size.width,size.height);
    UIGraphicsBeginImageContext(size);//创建图片
    CGContextRef context = UIGraphicsGetCurrentContext();//创建图片上下文
    CGContextSetFillColorWithColor(context, [color CGColor]);//设置当前填充颜色的图形上下文
    CGContextFillRect(context, rect);//填充颜色
    
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

相关文章

网友评论

      本文标题:用颜色UIColor生成图片UIImage

      本文链接:https://www.haomeiwen.com/subject/vwgxwttx.html