美文网首页
[iOS] 绘制纯色图片

[iOS] 绘制纯色图片

作者: manajay | 来源:发表于2018-04-26 13:57 被阅读38次
// 返回一张纯色图片
+ (UIImage *)lj_imageWithColor:(UIColor *)color rect:(CGRect)rect {

    // 开启位图上下文
    UIGraphicsBeginImageContext(rect.size);
    // 获取位图上下文
    CGContextRef context = UIGraphicsGetCurrentContext();
    // 使用color演示填充上下文
    CGContextSetFillColorWithColor(context, [color CGColor]);
    // 渲染上下文
    CGContextFillRect(context, rect);
    // 从上下文中获取图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    // 结束上下文
    UIGraphicsEndImageContext();
    
    return image;
}

相关文章

网友评论

      本文标题:[iOS] 绘制纯色图片

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