Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert RGB to HTML color?

Please can you tell me how I can convert an RGB UIColor to a Hexadecimal HTML color code string?

like image 755
max_ Avatar asked May 14 '11 14:05

max_


1 Answers

- (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)];
}
like image 154
taskinoor Avatar answered Oct 22 '22 21:10

taskinoor