How to convert RGB to HTML color?

Please tell how can I convert RGB UIColor to a hexadecimal string of HTML color code?

+6
source share
1 answer
 - (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)]; } 
+16
source

Source: https://habr.com/ru/post/888112/


All Articles