Eugene Zhenya Gordin Eugene Zhenya Gordin - 1 year ago 85
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?

Answer Source

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)];