How do I create a NSColor from a RGB value?
Per the NSColor documentation:
NSColor *myColor = [NSColor colorWithCalibratedRed:redValue green:greenValue blue:blueValue alpha:1.0f];
Also don't forget to do the following conversion from the actual RGB values you get, lets say from Photoshop...
an RGB of (226, 226, 226) could be instantiated as a NSColor using the values:
Red: 226/255 = 0.886...
Green: 226/255 = 0.886...
Blue: 226/255 = 0.886...
[NSColor colorWithDeviceRed:0.886f green:0.886f blue:0.886f alpha:1.0f];
Why 255? 8-bit color channels range from 0 to 255 (inclusive). When normalized this is scaled to the range [0,1] (inclusive). See references for conversions from normalized values to unnormalized values and vice versa.
float red = 0.5f;
float green = 0.2f;
float blue = 0.4f;
float alpha = 0.8f;
NSColor *rgb = [NSColor colorWithDeviceRed:red green:green blue:blue alpha:alpha];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With