如何将RGB转换为HTML颜色? [英] How to convert RGB to HTML color?

查看:205
本文介绍了如何将RGB转换为HTML颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何将RGB UIColor 转换为十六进制HTML颜色代码字符串?

解决方案

   - (的NSString *)getHexStringForColor:(的UIColor *)色{
常量CGFloat的* =组分CGColorGetComponents(color.CGColor);
CGFloat r =组件[0];
CGFloat g =组件[1];
CGFloat b =组件[2];

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


Please can you tell me how I can convert an RGB UIColor to 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)];
}

这篇关于如何将RGB转换为HTML颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆