3

如何将 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;
4

1 回答 1

3

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

unsigned int outVal;
NSScanner* scanner = [NSScanner scannerWithString:@"0xFF000000"];
[scanner scanHexInt:&outVal];
于 2013-08-28T13:43:12.743 回答