Question

How to convert UIColor object to uint32_t value. Please let me know if any one aware of this?

Here is the code:

const CGFloat *components = CGColorGetComponents([UIColor redColor].CGColor);
   CGFloat r = components[0];
   CGFloat g = components[1];
   CGFloat b = components[2];
  const  uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b);

How to pass 0xFFFFFFFF value in uint32_t?

 const uint32_t white = 0xFFFFFFFF, black = 0xFF000000, transp = 0x00FFFFFF;
Was it helpful?

Solution

If you want to convert hex-string to integer value, you should try this:

unsigned int outVal;
NSScanner* scanner = [NSScanner scannerWithString:@"0xFF000000"];
[scanner scanHexInt:&outVal];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top