iOS中 将 颜色转化成图片

定义一个类方法:
声明:
+ (UIImage *)imageFromColor:(UIColor *)color;
实现:
+ (UIImage *)imageFromColor:(UIColor *)color{
   
    CGRect rect = CGRectMake(0, 0, 3, 3);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}
posted @ 2016-10-11 11:07  小小鸟菜  阅读(1366)  评论(0编辑  收藏  举报