美文网首页
iOS颜色 图片 互转

iOS颜色 图片 互转

作者: MdWhat | 来源:发表于2016-11-24 17:27 被阅读429次

颜色 ---> 图片

- (UIImage *)createImageWithColor:(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 *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();  
    return theImage;
}

图片 ----> 颜色

UIImage *img = [UIImage imageNamed:@"xxx"];
UIColor *color = [UIColor colorWithPatternImage:img];

相关文章

网友评论

      本文标题:iOS颜色 图片 互转

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