Created
October 26, 2012 16:13
-
-
Save bjtitus/3959689 to your computer and use it in GitHub Desktop.
UIColor contrast additions
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
// | |
// UIColor+ContrastAdditions | |
// | |
// Created by Brandon Titus (bjtitus.net) on 10/26/12. | |
// | |
// | |
#import <UIKit/UIKit.h> | |
#import "UIColor-Expanded.h" | |
// Clone it from here: | |
// http://github.com/ars/uicolor-utilities | |
@interface UIColor (ContrastAdditions) | |
//Uses the Hex color values to tell you whether this UIColor contrasts well with black | |
-(BOOL)contrastsBlack50; | |
// Converts the color components to YIQ http://en.wikipedia.org/wiki/YIQ and tells you whether this UIColor contrasts well with black | |
-(BOOL)contrastsBlackYIQ; | |
@end |
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
// | |
// UIColor+ContrastAdditions.m | |
// | |
// Created by Brandon Titus (bjtitus.net) on 10/26/12. | |
// | |
// Released into the public domain | |
// Original idea: http://24ways.org/2010/calculating-color-contrast | |
#import "UIColor+ContrastAdditions.h" | |
@implementation UIColor (ContrastAdditions) | |
-(BOOL)contrastsBlack50 | |
{ | |
return ([self rgbHex] > 0xffffff/2); | |
} | |
-(BOOL)contrastsBlackYIQ | |
{ | |
float yiq = (((self.red*256)*299) + ((self.green*256)*587) + ((self.blue*256)*114))/1000; | |
return (yiq >=128); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment