Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone CGContextSetRGBFillColor中的十六进制颜色_Iphone_Objective C_Colors_Hex_Quartz Graphics - Fatal编程技术网

Iphone CGContextSetRGBFillColor中的十六进制颜色

Iphone CGContextSetRGBFillColor中的十六进制颜色,iphone,objective-c,colors,hex,quartz-graphics,Iphone,Objective C,Colors,Hex,Quartz Graphics,如果我有一些十六进制格式的颜色。。。如何在CGContextSetRGBFillColor(上下文,.?)中使用十六进制颜色 这是唯一的办法吗 NSString *color = @"0xe3f3fbff"; unsigned r,g,b,a; [[NSScanner scannerWithString:[color substringWithRange:NSMakeRange(2,2)]] scanHexInt:&r]; [[NSScanner scannerWithString

如果我有一些十六进制格式的颜色。。。如何在
CGContextSetRGBFillColor(上下文,.?)
中使用十六进制颜色

这是唯一的办法吗

NSString  *color = @"0xe3f3fbff";

unsigned r,g,b,a;

[[NSScanner scannerWithString:[color substringWithRange:NSMakeRange(2,2)]] scanHexInt:&r];
[[NSScanner scannerWithString:[color substringWithRange:NSMakeRange(4,2)]] scanHexInt:&g];
[[NSScanner scannerWithString:[color substringWithRange:NSMakeRange(6,2)]] scanHexInt:&b];
[[NSScanner scannerWithString:[color substringWithRange:NSMakeRange(7,2)]] scanHexInt:&a];

CGContextSetRGBFillColor(context,r/255.0,g/255.0,b/255.0,a/255.0);

这样做就可以了。链接到的副本的可能副本有这样做的代码。你的方法也可以,只要你把它放在某个函数中。