How do I create a NSColor from a RGB value?
+6
A:
Per the NSColor documentation:
NSColor *myColor = [NSColor colorWithCalibratedRed:redValue green:greenValue blue:blueValue alpha:1.0f];
Matt Ball
2009-12-21 05:29:51
You should use 1.0f instead of 1.0, as 1.0 is a double, which is not a native type for the iPhone.
nash
2009-12-21 05:33:05
You are correct — the perils of typing code quickly!
Matt Ball
2009-12-21 05:34:54
It's probably worth making it clear that the color values are from 0.0 to 1.0.Also, the "calibrated" version is indeed more than likely the correct variant of this method to use. You want to use the NSCalibratedRGBColorSpace (which corresponds to [NSColorSpace genericRGBColorSpace]) in all internal dealings with colors. And only use the "device" color spaces variants when outputting to a known specific device.
Kelan
2009-12-21 07:38:00
A:
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]
nash
2009-12-21 05:31:45