ios 根据颜色生成图片,十六进制颜色。

//颜色生成图片方法

- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {

    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;

}

 

 

//十六进制颜色

#define UIColorFromRGB(rgbValue) [UIColor \

colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \

green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \

blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

posted @ 2016-07-22 10:18  SoulDu  阅读(256)  评论(0编辑  收藏  举报