请告诉我如何将RGB UIColor
转换为十六进制HTML颜色代码字符串?
答案 0 :(得分:16)
- (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)];
}