R is the premultiplied result
S is the source color, and includes alpha
D is the destination color, and includes alpha
Ra, Sa, and Da are the alpha components of R, S, and D
// UIImage+Tint.m#import "UIImage+Tint.h"@implementationUIImage(Tint)-(UIImage*)imageWithTintColor:(UIColor*)tintColor{return[selfimageWithTintColor:tintColorblendMode:kCGBlendModeDestinationIn];}-(UIImage*)imageWithGradientTintColor:(UIColor*)tintColor{return[selfimageWithTintColor:tintColorblendMode:kCGBlendModeOverlay];}-(UIImage*)imageWithTintColor:(UIColor*)tintColorblendMode:(CGBlendMode)blendMode{//We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.UIGraphicsBeginImageContextWithOptions(self.size,NO,0.0f);[tintColorsetFill];CGRectbounds=CGRectMake(0,0,self.size.width,self.size.height);UIRectFill(bounds);//Draw the tinted image in context[selfdrawInRect:boundsblendMode:blendModealpha:1.0f];if(blendMode!=kCGBlendModeDestinationIn){[selfdrawInRect:boundsblendMode:kCGBlendModeDestinationInalpha:1.0f];}UIImage*tintedImage=UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();returntintedImage;}@end