title: Check if UIColor is dark or bright?
body: <p>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 readability.</p>
  
  <p>Here's an example in Flash/Actionscript (with demo):
  <a href="http://web.archive.org/web/20100102024448/http://theflashblog.com/?p=173" rel="noreferrer">http://web.archive.org/web/20100102024448/http://theflashblog.com/?p=173</a></p>
  
  <p>Any thoughts?</p>
  
  <p>Cheers,
  Andre</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to everyone's suggestions, here's the working code:</p>
  
  <pre><code>- (void) updateColor:(UIColor *) newColor
  {
      const CGFloat *componentColors = CGColorGetComponents(newColor.CGColor);
  
      CGFloat colorBrightness = ((componentColors[0] * 299) + (componentColors[1] * 587) + (componentColors[2] * 114)) / 1000;
      if (colorBrightness &lt; 0.5)
      {
          NSLog(@"my color is dark");
      }
      else
      {
          NSLog(@"my color is light");
      }
  }
  </code></pre>
  
  <p>Thanks once again :)</p>