CGBlendMode

- (UIImage *) imageWithTintColor:(UIColor *)tintColor blendMode:(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);
    [tintColor setFill];
    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
    UIRectFill(bounds);

    //Draw the tinted image in context
    [self drawInRect:bounds blendMode:blendMode alpha:1.0f];

    if (blendMode != kCGBlendModeDestinationIn) {
        [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
    }

    UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return tintedImage;
}

调用

self.ivStar.image = [[UIImage imageNamed:@"image"] imageWithTintColor:[UIColor orangeColor] blendMode:kCGBlendModePlusLighter];

原图
CGBlendMode_第1张图片

kCGBlendModeNormal
CGBlendMode_第2张图片

kCGBlendModeMultiply
CGBlendMode_第3张图片

kCGBlendModeScreen
CGBlendMode_第4张图片

kCGBlendModeOverlay
CGBlendMode_第5张图片

kCGBlendModeDarken
CGBlendMode_第6张图片

kCGBlendModeLighten
CGBlendMode_第7张图片

kCGBlendModeColorDodge
CGBlendMode_第8张图片

kCGBlendModeColorBurn
CGBlendMode_第9张图片

kCGBlendModeSoftLight
CGBlendMode_第10张图片

kCGBlendModeHardLight
CGBlendMode_第11张图片

kCGBlendModeDifference
CGBlendMode_第12张图片

kCGBlendModeExclusion
CGBlendMode_第13张图片

kCGBlendModeHue
CGBlendMode_第14张图片

kCGBlendModeSaturation
CGBlendMode_第15张图片

kCGBlendModeColor
CGBlendMode_第16张图片

kCGBlendModeLuminosity
CGBlendMode_第17张图片

kCGBlendModeClear
CGBlendMode_第18张图片

kCGBlendModeCopy
CGBlendMode_第19张图片

kCGBlendModeSourceIn
CGBlendMode_第20张图片

kCGBlendModeSourceOut
CGBlendMode_第21张图片

kCGBlendModeSourceAtop
CGBlendMode_第22张图片

kCGBlendModeDestinationOver
CGBlendMode_第23张图片

kCGBlendModeDestinationIn
CGBlendMode_第24张图片

kCGBlendModeDestinationOut
CGBlendMode_第25张图片

kCGBlendModeDestinationAtop
CGBlendMode_第26张图片

kCGBlendModeXOR
CGBlendMode_第27张图片

kCGBlendModePlusDarker
CGBlendMode_第28张图片

kCGBlendModePlusLighter
CGBlendMode_第29张图片

你可能感兴趣的:(学习)