Skip to content


iPhone RGB

September 27, 2010

Below are the macros that we can use for getting UIColor for the given RGB values. This way we need not create a UIColor object explicitly each time.

1. UIColor from RGB with default alpha set to 1.

#define RGB(r, g, b)
    [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]

2. UIColor from RGB with the alpha value.

#define RGBA(r, g, b, a)
 [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

3. UIColor from the Hexa color value.

#define UIColorFromRGB(rgbValue)
 [UIColor \ colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \  blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

From → iPad, iPhone

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: