diff --git a/FXBlurView/FXBlurView.h b/FXBlurView/FXBlurView.h index db872c9..01f99ac 100644 --- a/FXBlurView/FXBlurView.h +++ b/FXBlurView/FXBlurView.h @@ -32,7 +32,6 @@ #import -#import #pragma GCC diagnostic push @@ -51,6 +50,7 @@ @interface UIImage (FXBlurView) - (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor; +- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor tintBlendMode:(CGBlendMode)tintBlendMode; @end @@ -67,6 +67,7 @@ @property (nonatomic, assign) NSTimeInterval updateInterval; @property (nonatomic, assign) CGFloat blurRadius; @property (nonatomic, strong) UIColor *tintColor; +@property (nonatomic, assign) CGBlendMode tintBlendMode; @property (nonatomic, weak_ref) UIView *underlyingView; - (void)updateAsynchronously:(BOOL)async completion:(void (^)())completion; diff --git a/FXBlurView/FXBlurView.m b/FXBlurView/FXBlurView.m index 490e99b..c1adbe8 100755 --- a/FXBlurView/FXBlurView.m +++ b/FXBlurView/FXBlurView.m @@ -35,6 +35,7 @@ #import #import #import +#import #pragma GCC diagnostic ignored "-Wobjc-missing-property-synthesis" @@ -50,7 +51,11 @@ @implementation UIImage (FXBlurView) -- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor +- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor { + return [self blurredImageWithRadius:radius iterations:iterations tintColor:tintColor tintBlendMode:kCGBlendModeLighten]; +} + +- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor tintBlendMode:(CGBlendMode)tintBlendMode { //image must be nonzero size if (floorf(self.size.width) * floorf(self.size.height) <= 0.0f) return self; @@ -101,8 +106,8 @@ - (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)itera //apply tint if (tintColor && CGColorGetAlpha(tintColor.CGColor) > 0.0f) { - CGContextSetFillColorWithColor(ctx, [tintColor colorWithAlphaComponent:0.25].CGColor); - CGContextSetBlendMode(ctx, kCGBlendModePlusLighter); + CGContextSetFillColorWithColor(ctx, tintColor.CGColor); + CGContextSetBlendMode(ctx, tintBlendMode); CGContextFillRect(ctx, CGRectMake(0, 0, buffer1.width, buffer1.height)); } @@ -158,6 +163,7 @@ @interface FXBlurView () @property (nonatomic, assign) BOOL blurRadiusSet; @property (nonatomic, assign) BOOL dynamicSet; @property (nonatomic, assign) BOOL blurEnabledSet; +@property (nonatomic, assign) BOOL tintBlendModeSet; @property (nonatomic, strong) NSDate *lastUpdate; - (UIImage *)snapshotOfUnderlyingView; @@ -308,6 +314,7 @@ - (void)setUp if (!_blurRadiusSet) [self blurLayer].blurRadius = 40; if (!_dynamicSet) _dynamic = YES; if (!_blurEnabledSet) _blurEnabled = YES; + if(!_tintBlendModeSet) _tintBlendMode = kCGBlendModeLighten; self.updateInterval = _updateInterval; self.layer.magnificationFilter = @"linear"; // kCAFilterLinear @@ -429,6 +436,12 @@ - (void)setTintColor:(UIColor *)tintColor [self setNeedsDisplay]; } +- (void)setTintBlendMode:(CGBlendMode)tintBlendMode { + _tintBlendModeSet = YES; + _tintBlendMode = tintBlendMode; + [self setNeedsDisplay]; +} + - (void)didMoveToSuperview { [super didMoveToSuperview]; @@ -572,7 +585,8 @@ - (UIImage *)blurredSnapshot:(UIImage *)snapshot radius:(CGFloat)blurRadius { return [snapshot blurredImageWithRadius:blurRadius iterations:self.iterations - tintColor:self.tintColor]; + tintColor:self.tintColor + tintBlendMode:self.tintBlendMode]; } - (void)setLayerContents:(UIImage *)image