开发者

How to convert RGB to HTML color?

开发者 https://www.devze.com 2023-03-05 17:17 出处:网络
Please can you tell me how I can convert an RGB UIColor t开发者_高级运维o a Hexadecimal HTML color code string?- (NSString *)getHexStringForColor:(UIColor*)color {

Please can you tell me how I can convert an RGB UIColor t开发者_高级运维o a Hexadecimal HTML color code string?


- (NSString *)getHexStringForColor:(UIColor*)color {
    const CGFloat *components = CGColorGetComponents(color.CGColor);
    CGFloat r = components[0];
    CGFloat g = components[1];
    CGFloat b = components[2];

    return [NSString stringWithFormat:@"%02X%02X%02X", (int)(r * 255), (int)(g * 255), (int)(b * 255)];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消