利用颜色值来生成UIImage

来源:互联网 发布:搜狐网络大厦地铁路线 编辑:程序博客网 时间:2024/06/05 08:12

只通过一个方法就可以完成此功能,直接上代码:

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

{

    CGRect rect = CGRectMake(0.0f0.0f1.0f1.0f);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    CGContextSetFillColorWithColor(context, [color CGColor]);

    CGContextFillRect(context, rect);

    

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return image;

}

0 0
原创粉丝点击