priore

Fade from color to color

Apr 3rd, 2017
592
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (UIColor *)fadeFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor withPercentage:(CGFloat)percentage
  2. {
  3.     // get the RGBA values from the colours
  4.     CGFloat fromRed, fromGreen, fromBlue, fromAlpha;
  5.     [fromColor getRed:&fromRed green:&fromGreen blue:&fromBlue alpha:&fromAlpha];
  6.    
  7.     CGFloat toRed, toGreen, toBlue, toAlpha;
  8.     [toColor getRed:&toRed green:&toGreen blue:&toBlue alpha:&toAlpha];
  9.    
  10.     //calculate the actual RGBA values of the fade colour
  11.     CGFloat red = (toRed - fromRed) * percentage + fromRed;
  12.     CGFloat green = (toGreen - fromGreen) * percentage + fromGreen;
  13.     CGFloat blue = (toBlue - fromBlue) * percentage + fromBlue;
  14.     CGFloat alpha = (toAlpha - fromAlpha) * percentage + fromAlpha;
  15.    
  16.     // return the fade colour
  17.     return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
  18. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×