美文网首页iOS开发
iOS 根据颜色值来生成UIImage

iOS 根据颜色值来生成UIImage

作者: Pandakingli | 来源:发表于2017-02-10 11:50 被阅读8次

代码如下:

-(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 根据颜色值来生成UIImage

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