UIcolor转UIImage

+ (UIImage *)imageWithColor:(UIColor *)color {

    

    CGRect rect = CGRectMake(0, 0, 1, 1);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);

    CGContextFillRect(context, rect);

    

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;

}

posted @ 2017-03-13 11:58  超神船长  阅读(311)  评论(0编辑  收藏  举报