Hex/HTML Color (RGBA, RGB) to UIColor

#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0 \
                                    green:((c>>16)&0xFF)/255.0 \
                                     blue:((c>>8)&0xFF)/255.0 \
                                    alpha:((c)&0xFF)/255.0]

Usage: UIColor *c = HEXCOLOR(0xff0000);.

If you want a macro for RGB (above is for RGBA), replace alpha: with alpha:1.0.

Courtesy of this thread.

Comments