Skip to content

Commit

Permalink
Added isEqualToColor method.
Browse files Browse the repository at this point in the history
  • Loading branch information
rokgregoric committed Jun 20, 2014
1 parent 4cd8b33 commit aafa472
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions RGHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@interface UIColor (IntegerConversion)

+ (UIColor *)colorWithInt:(NSInteger)number;
- (BOOL)isEqualToColor:(UIColor *)otherColor;

@end

Expand Down
24 changes: 24 additions & 0 deletions RGHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ + (UIColor *)colorWithInt:(NSInteger)number {
alpha:1];
}

- (BOOL)isEqualToColor:(UIColor *)otherColor {
if (self == otherColor) return YES;

CGColorSpaceRef colorSpaceRGB = CGColorSpaceCreateDeviceRGB();

UIColor *(^convertColorToRGBSpace)(UIColor *) = ^(UIColor *color) {
if (CGColorSpaceGetModel(CGColorGetColorSpace(color.CGColor)) == kCGColorSpaceModelMonochrome) {
const CGFloat *oldComponents = CGColorGetComponents(color.CGColor);
CGFloat components[4] = {oldComponents[0], oldComponents[0], oldComponents[0], oldComponents[1]};
CGColorRef colorRef = CGColorCreate(colorSpaceRGB, components);
UIColor *color = [UIColor colorWithCGColor:colorRef];
CGColorRelease(colorRef);
return color;
}
return color;
};

UIColor *selfColor = convertColorToRGBSpace(self);
otherColor = convertColorToRGBSpace(otherColor);
CGColorSpaceRelease(colorSpaceRGB);

return [selfColor isEqual:otherColor];
}

@end

#pragma mark - NSString (UrlEncoding)
Expand Down

0 comments on commit aafa472

Please sign in to comment.