0

if i have some colors in hex format... how can i use a hex color in CGContextSetRGBFillColor(context, .?.) ?

Is this the only way?

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);
STW
  • 44,917
  • 17
  • 105
  • 161
Safari
  • 11,437
  • 24
  • 91
  • 191

0 Answers0