美文网首页ios开发
ios开发 根据颜色生成图片

ios开发 根据颜色生成图片

作者: 863cda997e42 | 来源:发表于2017-09-18 08:52 被阅读135次

    次方法传人颜色值,返回对应颜色的图片。

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

    相关文章

      网友评论

        本文标题:ios开发 根据颜色生成图片

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