之前见过这个问题,但我的示例似乎不起作用。
const CGFloat *toCol = CGColorGetComponents([[UIColor greenColor] CGColor]);
用 GDB 查看该数组是空的。有什么提示吗?
最佳答案
您提供的代码示例应该可以工作。
试试这个:
UIColor uicolor = [[UIColor greenColor] retain];
CGColorRef color = [uicolor CGColor];
int numComponents = CGColorGetNumberOfComponents(color);
if (numComponents == 4)
{
const CGFloat *components = CGColorGetComponents(color);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
CGFloat alpha = components[3];
}
[uicolor release];
关于iphone - 从 UIColor 中提取 RGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/816828/