美文网首页
iOS 返回一个纯色的image

iOS 返回一个纯色的image

作者: 明似水 | 来源:发表于2017-02-18 12:06 被阅读173次
纯色image

//返回一个纯色的image

+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
    
        CGRect rect = CGRectMake(0, 0, size.width, size.height);
    
        UIGraphicsBeginImageContext(rect.size);
    
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        CGContextSetFillColorWithColor(context, [color CGColor]);
    
        CGContextFillRect(context, rect);
    
    
    
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
        UIGraphicsEndImageContext();
    
        return image;
    
}

相关文章

网友评论

      本文标题:iOS 返回一个纯色的image

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