Last active
August 29, 2015 14:08
-
-
Save douglashill/2c3d70b65d171b2e36b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @implementation NSColor (DHLuminance) | |
| - (CGFloat)dh_luminance | |
| { | |
| return 0.3 * [self redComponent] + 0.6 * [self greenComponent] + 0.1 * [self blueComponent]; | |
| } | |
| @end | |
| // Example usage for an attributed string: | |
| // NSForegroundColorAttributeName : [colour dh_luminance] > 0.45 ? [NSColor blackColor] : [NSColor colorWithWhite:0.9 alpha:1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment