Re: NSColor question
Re: NSColor question
- Subject: Re: NSColor question
- From: Todd Yandell <email@hidden>
- Date: Mon, 25 Apr 2005 12:11:12 -0500
Hi,
Here's a simple category on NSColor that might help you:
/* Examples:
NSColor *red = [NSColor colorWithRGBString:@"255, 0, 0"];
NSColor *yellow = [NSColor colorWithRGBAString:@"255,255,0,128"];
*/
@implementation NSColor ( RGBStringAdditions )
+ (NSColor *)colorWithRGBString:(NSString *)string
{
NSArray *channels = [string componentsSeparatedByString:@","];
NSColor *color = [NSColor colorWithDeviceRed:
[[channels objectAtIndex:0] floatValue] / 255.0
green:[[channels objectAtIndex:1] floatValue] / 255.0
blue:[[channels objectAtIndex:2] floatValue] / 255.0
alpha:1.0];
return color;
}
+ (NSColor *)colorWithRGBAString:(NSString *)string
{
NSArray *channels = [string componentsSeparatedByString:@","];
NSColor *color = [NSColor colorWithDeviceRed:
[[channels objectAtIndex:0] floatValue] / 255.0
green:[[channels objectAtIndex:1] floatValue] / 255.0
blue:[[channels objectAtIndex:2] floatValue] / 255.0
alpha:[[channels objectAtIndex:3] floatValue] / 255.0];
return color;
}
Todd Yandell
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden