Eugene Zhenya Gordin Eugene Zhenya Gordin - 2 months ago 20
Objective-C Question

Getting a hex value from NSColor in Cocoa?

Does anyone know if it's possible to get a hexadecimal value of the color from NSColor in Cocoa?

SG1 SG1
Answer

Example using blue NSColor:

NSColor* color = [NSColor blueColor];

NSString* hexString = [NSString stringWithFormat:@"%02X%02X%02X", 
(int) (color.redComponent * 0xFF), (int) (color.greenComponent * 0xFF), 
(int) (color.blueComponent * 0xFF)];
Comments