• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSColor question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >NSColor question (From: Luc Vandal <email@hidden>)

  • Prev by Date: How do you call a method of a super view?
  • Next by Date: NSImage from a url
  • Previous by thread: Re: NSColor question
  • Next by thread: Where was the mouse clicked????
  • Index(es):
    • Date
    • Thread