本文介绍了从UIColor中提取rgb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
之前看过这个问题,但我的例子似乎没有用。
Seen this asked before but my example does not seem to work.
const CGFloat *toCol = CGColorGetComponents([[UIColor greenColor] CGColor]);
使用GDB查看数组是空的。任何提示?
The array is empty from looking at it with GDB. Any hints?
推荐答案
您提供的代码示例应该有效。
The code sample you provided should work.
试试这个:
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];
这篇关于从UIColor中提取rgb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!