Re: color
Re: color
- Subject: Re: color
- From: "John C. Randolph" <email@hidden>
- Date: Thu, 29 May 2003 21:44:43 -0700
On Thursday, May 29, 2003, at 03:11 PM, Rhon Fitzwater wrote:
Can some one tell me how to set NSColor so it is this hex color
(#33CCFF ) which can be seen at
http://hotwired.lycos.com/webmonkey/reference/color_codes/
Right now I have this as my code: [NSColor cyanColor] but that color
is noticably different than what I want. If someone can help me with
the code that would be great.
Well, +cyanColor would give you a color corresponding to 00FFFF (No
red, max green and blue), so that isn't surprising.
OK, two hex digits gives you a range from 0 to 255 (decimal), which you
need to map to a range of 0 to 1, so:
NSColor *myColor =
[NSColor colorWithCalibratedRed: 0x33/255.0 // dividing a hex integer
constant by a decimal float constant works fine..
green: 0xCC/255.0
blue: 0xFF/255.0
alpha: 1.0]; // Opaque
Using +colorWithCalibratedRed:green:blue:alpha: will do the right thing
w/r/t ColorSync. You could also use
+colorWithDeviceRed:green:blue:alpha, but that will rarely be what you
need.
Hope this helps,
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >color (From: Rhon Fitzwater <email@hidden>) |