Featured Apps


Create Your Own Memes
Add captions to the most popular meme images or your own photos


Create Photo Collages
Easily create photo collages to share with friends and family


Music Alarm Clock
Simple, stylist and intuitive music alarm clock

Create UIColor from hex string

16 October 2013

When designing, we often find ourselves using hex strings for our colours. When we start working on an iPhone app, we know need to use UIColor's instead. This function below will allow you to easily convert your hex value into a UIColor.

-(UIColor *)colorFromHex:(NSString *)hex {
    unsigned int c;
    if ([hex characterAtIndex:0] == '#') {
        [[NSScanner scannerWithString:[hex substringFromIndex:1]] scanHexInt:&c];
    } else {
        [[NSScanner scannerWithString:hex] scanHexInt:&c];
    return [UIColor colorWithRed:((c & 0xff0000) >> 16)/255.0 
                           green:((c & 0xff00) >> 8)/255.0 
                            blue:(c & 0xff)/255.0 alpha:1.0];