Create a new class file of color
#import "Uicolor+hex.h"
+ (uicolor*) colorwithhexstring: (NSString *) color alpha: (cgfloat) alpha{//delete string space nsstring *cstring =[[color Stringby Trimmingcharactersinset:[nscharacterset Whitespaceandnewlinecharacterset]] uppercasestring]; if ([cString length] <6) {return [Uicolor Clearcolor]; } if ([CString hasprefix:@ "0X"]) {cString = [cString substringfromindex:2]; } if ([CString hasprefix:@ "#"]) {cString = [cString substringfromindex:1]; } if ([cString length]!=6) {return [Uicolor Clearcolor]; } Nsrange range; range.location = 0; Range.length = 2; NSString *rstring = [cString substringwithrange:range]; Range.location = 2; NSString *gstring = [cString substringwithrange:range]; Range.location = 4; NSString *bstring =[cstring Substringwithrange:range]; unsigned r,g,b; [[Nsscanner scannerwithstring:rstring]scanhexint:&r]; [[Nsscanner scannerwithstring:gstring]scanhexint:&g]; [[NsscanNER scannerwithstring:bstring]scanhexint:&b]; return [Uicolor colorwithred: ((float) r/255.0f) Green: ((float) g/255.0f) Blue: ((float) b/255.0f) Alpha:alpha]; }+ (uicolor*) colorwithhexstring: (NSString *) color{return [self Colorwithhexstring:color alpha:1.0f];}
iOS development--color support hex