美文网首页
2019-03-22

2019-03-22

作者: Angel_梅丹佐 | 来源:发表于2019-03-22 15:29 被阅读0次

    iOS 根据给定的颜色(Color)生成 image

    废话不多说直接上代码:

    /*
      color :需要生成的图片颜色
     返回 一个  UIImage 类型的 image
    */
    + (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;
    }
    

    相关文章

      网友评论

          本文标题:2019-03-22

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