The code you point to moves the color up or down by 0.2 in the first code example and adjusts the brightness in the second.
In the middle of the color, I assume that you mean one of two things: (1) the color itself or (2) something is not as light or as dark as in the code example. To achieve the latter, all you have to do is change the brightness factor, for example.
@implementation UIColor (LightAndDark) - (UIColor *)lighterColor { CGFloat h, s, b, a; if ([self getHue:&h saturation:&s brightness:&b alpha:&a]) return [UIColor colorWithHue:h saturation:s brightness:MIN(b * 1.15, 1.0) alpha:a]; return nil; } - (UIColor *)darkerColor { CGFloat h, s, b, a; if ([self getHue:&h saturation:&s brightness:&b alpha:&a]) return [UIColor colorWithHue:h saturation:s brightness:b * 0.85 alpha:a]; return nil; } @end
Or is it that you are looking for a color between two colors? Work on this will now edit again soon.
Update: for medium color:
- (UIColor *)betweenColor:(UIColor *)c andColor:(UIColor *)d { CGFloat r, g, b, a; CGFloat r2, g2, b2, a2; [c getRed:&r green:&g blue:&b alpha:&a]; [d getRed:&r2 green:&g2 blue:&b2 alpha:&a2]; return [UIColor colorWithRed:(r + r2)/2 green:(g + g2)/2 blue:(b + b2)/2 alpha:a]; return nil; }
and name it as follows:
UIColor *midColor = [self betweenColor:[UIColor whiteColor] andColor:[UIColor blackColor]]; self.view.backgroundColor = midColor;
and here is the midpoint of HSB:
- (UIColor *)betweenColor:(UIColor *)c andColor:(UIColor *)d { CGFloat h, s, b, a; CGFloat h2, s2, b2, a2; [c getHue:&h saturation:&s brightness:&b alpha:&a]; [d getHue:&h2 saturation:&s2 brightness:&b2 alpha:&a2]; return [UIColor colorWithHue:(h+h2)/2 saturation:(s+s2)/2 brightness:(b+b2)/2 alpha:a]; return nil; }