Iphone 如何实现c++;iOS中的setRGB
我有大的int值Iphone 如何实现c++;iOS中的setRGB,iphone,ios,objective-c,colors,Iphone,Ios,Objective C,Colors,我有大的int值RGB=4294967295 如何从该值设置颜色?在C++中,我可以使用 SETrgB*()/Case>方法。如何在iOS中实现它?您可以像这样使用位运算符: float alpha = (intARGB >> 24) % 256; float red = (intARGB >> 16) % 256; float green = (intARGB >> 8) % 256; float blue = intARGB % 256; UIColor
RGB=4294967295代码>
如何从该值设置颜色?在C++中,我可以使用<代码> SETrgB*()/Case>方法。如何在iOS中实现它?您可以像这样使用位运算符:
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.];
您可以像这样使用位运算符:
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.];
但最好使用
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];
但最好使用
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];
您的实际数据格式是什么?组件如何连接到int?“它不起作用”不是很好的描述。。还可以看到这个帖子:当我使用你的代码时,我是黑色的。在控制台中,我有一个colorNum-4294944000 UIDeviceRGBColorSpace 1 0.498039U是正确的。我在你的代码中使用了int,代码取int值的最大范围21。。。。。并且总是给出黑色)您的实际数据格式是什么?组件如何连接到int?“它不起作用”不是很好的描述。。还可以看到这个帖子:当我使用你的代码时,我是黑色的。在控制台中,我有一个colorNum-4294944000 UIDeviceRGBColorSpace 1 0.498039U是正确的。我在你的代码中使用了int,代码取int值的最大范围21。。。。。并且总是给黑色)