0

我有很大的 int 值RGB = 4294967295; 如何从这个值设置颜色?在 c++ 中,我可以使用setRGB()方法。我怎样才能在iOS中制作它?

4

2 回答 2

4

您可以像这样使用按位运算符:

float alpha = (intARGB >> 24) % 256;
float red = (intARGB >> 16) % 256;
float green = (intARGB >> 8) % 256;
float blue = intARGB % 256;
UIColor *theColor = [UIColor colorWithRed:red/255. green:green/255. blue:blue/255. alpha:alpha/255.];
于 2013-03-04T10:44:11.053 回答
1

但更好用

unsigned char alpha = (color >> 24) & 0xff;
unsigned char red = (color >> 16) & 0xff;
unsigned char green = (color  >> 8) &0xff;
unsigned char blue = color &0xff;
UIColor *theColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
于 2013-03-04T12:23:48.693 回答