#define Default_void_color [Uicolor Whitecolor]+ (Uicolor *) colorwithhexstring: (NSString *) stringtoconvert{nsstring *cstring = [[Stringtoconvert stringByTrimmingCha Ractersinset:[nscharacterset Whitespaceandnewlinecharacterset]] uppercasestring]; if ([cString length] < 6) return default_void_color; if ([CString hasprefix:@ "#"]) cString = [cString substringfromindex:1]; if ([cString length]! = 6) return default_void_color; 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 int 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:1.0F];}
|
iOS tools 16 binary color to Uicolor