美文网首页
16进制颜色以及用颜色生成图片的代码

16进制颜色以及用颜色生成图片的代码

作者: 大雪山大轮寺大轮明王 | 来源:发表于2018-07-13 15:04 被阅读0次

把16进制转换成颜色的宏定义:

#define UIColorFromHex(s) [UIColor colorWithRed:(((s & 0xFF0000) >> 16))/255.0 green:(((s & 0xFF00) >> 8))/255.0 blue:((s & 0xFF))/255.0 alpha:1.0]

#define UIColorFromHexA(s, a) [UIColor colorWithRed:(((s & 0xFF0000) >> 16))/255.0 green:(((s & 0xFF00) >> 8))/255.0 blue:((s & 0xFF))/255.0 alpha:a]

#define UIColorFromRGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

用颜色生成图片的代码:

//用颜色创建一张图片

+ (UIImage *)createImageWithColor:(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;

}

相关文章

网友评论

      本文标题:16进制颜色以及用颜色生成图片的代码

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