图片

来源:互联网 发布:杰拉网咖 知乎 编辑:程序博客网 时间:2024/04/28 19:23

iOS

// 根据 color 得到 image
+ (UIImage *)imageWithColor:(UIColor *)color rect:(CGRect)rect {

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context,
                                   color.CGColor);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return img;
}



0 0
原创粉丝点击