Familiar with the CSS are aware of this, 16 binary such as: #666666
Http://blog.sina.com.cn/s/blog_5816f6a101019imm.html
This is for the value,
Find the 16-binary color table,
Self . View. BackgroundColor = [self colorwithhexstring:@ "#fff0f5"];
-(uicolor *) colorwithhexstring: (nsstring *) color
{
nsstring *cstring = [[Color stringbytrimmingcharactersinset: [ Nscharactersetwhitespaceandnewlinecharacterset]] uppercasestring];
//String should be 6 or 8 characters
if ([cString length] < 6) {
return [uicolorclearcolor];
}
//strip 0X if it appears
if ([cString hasprefix:@ "0X"])
cString = [cString substringfromindex: 2];
if ([cString hasprefix:@ "#"])
cString = [cString substringfromindex: 1];
if ([cString length]! = 6)
return [uicolorclearcolor];
//separate into R, G, B substrings
nsrange Range;
Range. location = 0;
Range. length = 2;
//r
nsstring *rstring = [cString substringwithrange: Range];
//g
Range. location = 2;
nsstring *gstring = [cString substringwithrange: Range];
//b
Range. location = 4;
nsstring *bstring = [cString substringwithrange: Range];
//Scan values
unsigned int R, G, B;
[[nsscannerscannerwithstring: rString] scanhexint:&r];
[[nsscannerscannerwithstring: gstring] scanhexint:&g];
[[nsscannerscannerwithstring: bstring] scanhexint:&b];
return [uicolor colorwithred:((float) r/255.0f) Green:((float) g/255.0f) Blue:((float) b/255.0f) Alpha: 1.0f ];
}