我需要确定用户选择的UIColor(由用户选择)是暗色还是亮色,以便我可以更改文本行的颜色,使其更易读。有关Flash / Actionscript的示例,请参见以下链接(附有演示):http://web.archive.org/web/20100102024448/http://theflashblog.com/?p=173 你有什么想法吗?谢谢!
- (void) updateColor:(UIColor *) newColor
{
const CGFloat *componentColors = CGColorGetComponents(newColor.CGColor);
CGFloat colorBrightness = ((componentColors[0] * 299) + (componentColors[1] * 587) + (componentColors[2] * 114)) / 1000;
if (colorBrightness < 0.5)
{
NSLog(@"my color is dark");
}
else
{
NSLog(@"my color is light");
}
}
再次感谢你 :)