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

本文来自 codeday ,作者 codeday
如何将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;

最佳答案
如果要将十六进制字符串转换为整数值,则应尝试以下操作:
unsigned int outVal;
NSScanner* scanner = [NSScanner scannerWithString:@"0xFF000000"];
[scanner scanHexInt:&outVal];

 

posted @ 2021-07-06 10:00  brave-sailor  阅读(299)  评论(0编辑  收藏  举报