Skip to content

Instantly share code, notes, and snippets.

@nek023
Created March 15, 2014 08:40
@interface UIColor (HSBFunctions)
- (UIColor *)lightenedColorByPercent:(CGFloat)percent;
- (UIColor *)darkenedColorByPercent:(CGFloat)percent;
@end
#import "UIColor+HSBFunctions.h"
@implementation UIColor (HSBFunctions)
- (UIColor *)lightenedColorByPercent:(CGFloat)percent
{
CGFloat hue, saturation, brightness, alpha;
[self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
return [UIColor colorWithHue:hue saturation:saturation brightness:(brightness + 1.0 * (percent / 100.0)) alpha:alpha];
}
- (UIColor *)darkenedColorByPercent:(CGFloat)percent
{
CGFloat hue, saturation, brightness, alpha;
[self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
return [UIColor colorWithHue:hue saturation:saturation brightness:(brightness - 1.0 * (percent / 100.0)) alpha:alpha];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment