通过UIColor创建图片

来源:互联网 发布:钢铁力量天蝎数据 编辑:程序博客网 时间:2024/05/18 13:28

不多说,代码如下:

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

{

    CGRect rect = CGRectMake(0, 0, 1, 1);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef contTextRef = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(contTextRef, [color CGColor]);

    CGContextFillRect(contTextRef, rect);

    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndPDFContext();

    return image;

}

0 0
原创粉丝点击