How to convert UIColor RGB Color to uint32_t Value

3.1k views Asked by At

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;
1

There are 1 answers

2
Valentin Shamardin On BEST ANSWER

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];