如何将RGB转换为HTML颜色?

请你能告诉我如何将RGB UIColor转换为hexHTML颜色代码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)]; }