您的位置:首页 > 产品设计 > UI/UE

iOS开发,用UIColor创建UIImage

2015-03-10 20:03 381 查看
+(UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {

    

    @autoreleasepool {

        
       
CGRect rect = CGRectMake(0,
0, size.width, size.height);

        UIGraphicsBeginImageContext(rect.size);

        CGContextRef context =
UIGraphicsGetCurrentContext();

        CGContextSetFillColorWithColor(context, color.CGColor);
       
CGContextFillRect(context, rect);

        

        UIImage *img =
UIGraphicsGetImageFromCurrentImageContext();

        

        UIGraphicsEndImageContext();

        
       
return img;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS UIImage UIColor
相关文章推荐