FROM : Todd Yandell
DATE : Mon Apr 25 19:11:12 2005
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;
}
@end
Todd Yandell
DATE : Mon Apr 25 19:11:12 2005
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;
}
@end
Todd Yandell
| Related mails | Author | Date |
|---|---|---|
| Luc Vandal | Apr 25, 18:04 | |
| James Housley | Apr 25, 18:12 | |
| Nicko van Someren | Apr 25, 18:15 | |
| Stephane Sudre | Apr 25, 18:19 | |
| Todd Yandell | Apr 25, 19:11 |






Cocoa mail archive

