Transferred from: http://lizhuang.iteye.com/blog/1931768
//rgb Color macro#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] RGB color macro with Alpha#define Uicolorfromrgbwithalpha (rgbvalue,a) [Uicolor colorwithred: ((float) (Rgbvalue & 0xFF0000) >>/255.0 Green: ((float) ((Rgbvalue & 0xff00) >> 8)/255.0 Blue: ((float) (Rgbvalue & 0xFF))/255.0 alpha:a]//16 binary string converted to int+ (ID) Colorwithhex: (NSString *) hex Alpha: (cgfloat) alpha{nsassert (7 = = Hex.len Gth, @ "Hex color format error!"); unsigned color = 0; Nsscanner *hexvaluescanner = [Nsscanner scannerwithstring:[hex substringfromindex:1]; [Hexvaluescanner scanhexint:&color]; int blue = color & 0xFF; int green = (color >> 8) & 0xFF; int red = (color >>) & 0xFF; return [Uicolor colorwithred:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0];} ?