kwigbo

Adventures in iOS!

3 notes

iPhone SDK Using Hex Values For UIColor

Here is a simple category to make using hex values for UIColor easier.

// UIColor+Hex.h
@interface UIColor (Hex)
 
+ (UIColor *) colorWithHex:(uint) hex;
 
@end
 
// UIColor+Hex.m
#import "UIColor+Hex.h"
 
@implementation UIColor (Hex)
 
+ (UIColor *) colorWithHex:(uint) hex
{
	int red, green, blue, alpha;
 
	blue = hex & 0x000000FF;
	green = ((hex & 0x0000FF00) >> 8);
	red = ((hex & 0x00FF0000) >> 16);
	alpha = ((hex & 0xFF000000) >> 24);
 
	return [UIColor colorWithRed:red/255.0f 
                               green:green/255.0f 
                               blue:blue/255.0f 
                               alpha:alpha/255.f];
}
 
@end

Filed under snippet iphone iphone dev

  1. kwigbo posted this