-
-
Save jamesnesfield/8807331 to your computer and use it in GitHub Desktop.
This file contains 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
//http://stackoverflow.com/questions/15757872/manually-color-fading-from-one-uicolor-to-another | |
- (UIColor *)colorFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor amount:(float)amount // 0 < amount < 1 | |
{ | |
float dec = amount; | |
CGFloat fRed, fBlue, fGreen, fAlpha; | |
CGFloat tRed, tBlue, tGreen, tAlpha; | |
CGFloat red, green, blue, alpha; | |
if(CGColorGetNumberOfComponents(fromColor.CGColor) == 2) { | |
[fromColor getWhite:&fRed alpha:&fAlpha]; | |
fGreen = fRed; | |
fBlue = fRed; | |
} | |
else { | |
[fromColor getRed:&fRed green:&fGreen blue:&fBlue alpha:&fAlpha]; | |
} | |
if(CGColorGetNumberOfComponents(toColor.CGColor) == 2) { | |
[toColor getWhite:&tRed alpha:&tAlpha]; | |
tGreen = tRed; | |
tBlue = tRed; | |
} | |
else { | |
[toColor getRed:&tRed green:&tGreen blue:&tBlue alpha:&tAlpha]; | |
} | |
red = (dec * (tRed - fRed)) + fRed; | |
green = (dec * (tGreen - fGreen)) + fGreen; | |
blue = (dec * (tBlue - fBlue)) + fBlue; | |
alpha = (dec * (tAlpha - fAlpha)) + fAlpha; | |
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment