How to convert RGB to HTML color?

前端 未结 1 717
北恋
北恋 2021-01-18 12:55

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

相关标签:
1条回答
  • 2021-01-18 13: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)];
    }
    
    0 讨论(0)
提交回复
热议问题