如何将UIColor RGB颜色转换为uint32_t值

时间:2013-08-28 13:39:14

标签: ios uicolor uint32-t

如何将UIColor对象转换为uint32_t值。如果有人意识到这一点,请告诉我?

以下是代码:

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

如何在uint32_t中传递0xFFFFFFFF值?

 const uint32_t white = 0xFFFFFFFF, black = 0xFF000000, transp = 0x00FFFFFF;

1 个答案:

答案 0 :(得分:3)

如果要将十六进制字符串转换为整数值,请尝试以下操作:

unsigned int outVal;
NSScanner* scanner = [NSScanner scannerWithString:@"0xFF000000"];
[scanner scanHexInt:&outVal];