I need to determine whether a selected UIColor (picked by the user) is dark or bright, so I can change the color of a line of text that sits on top of that color, for better
If you prefer the block version:
BOOL (^isDark)(UIColor *) = ^(UIColor *color){ const CGFloat *component = CGColorGetComponents(color.CGColor); CGFloat brightness = ((component[0] * 299) + (component[1] * 587) + (component[2] * 114)) / 1000; if (brightness < 0.75) return YES; return NO; };