Return to Snippet

Revision: 52139
at October 14, 2011 03:47 by suibhne


Initial Code
+ (UIColor *) colorFromHexRGB:(NSString *) inColorString
{
	UIColor *result = nil;
	unsigned int colorCode = 0;
	unsigned char redByte, greenByte, blueByte;
	
	if (nil != inColorString)
	{
		NSScanner *scanner = [NSScanner scannerWithString:inColorString];
		(void) [scanner scanHexInt:&colorCode];	// ignore error
	}
	redByte		= (unsigned char) (colorCode >> 16);
	greenByte	= (unsigned char) (colorCode >> 8);
	blueByte	= (unsigned char) (colorCode);	// masks off high bits
	result = [UIColor
            colorWithRed:	(float)redByte	/ 0xff
            green:	(float)greenByte/ 0xff
            blue:	(float)blueByte	/ 0xff
            alpha:1.0];    
	return result;
}

Initial URL


Initial Description
Code that will convert a simple Hex code value (from HTML colors) to an actual useable NSColor.

Initial Title
HTML Hex Color to NSColor

Initial Tags
iphone

Initial Language
Objective C