用一个颜色值生成一张图片

来源:互联网 发布:mac版 iphoto 编辑:程序博客网 时间:2024/06/03 12:15

有的时候我们需要用一个颜色值生成一张按钮的背景色,下面的方法就很有用了


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

{

    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context =UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [colorCGColor]);

    CGContextFillRect(context, rect);

    UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return theImage;

}


1 0
原创粉丝点击