Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FXBlurView#tintBlendMode #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions FXBlurView/FXBlurView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
@property (nonatomic, assign) NSTimeInterval updateInterval;
@property (nonatomic, assign) CGFloat blurRadius;
@property (nonatomic, strong) UIColor *tintColor;
@property (nonatomic, assign) NSUInteger tintBlendMode;
@property (nonatomic, weak_ref) UIView *underlyingView;

- (void)updateAsynchronously:(BOOL)async completion:(void (^)())completion;
Expand Down
20 changes: 18 additions & 2 deletions FXBlurView/FXBlurView.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
@implementation UIImage (FXBlurView)

- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor
{
return [self blurredImageWithRadius:radius iterations:iterations tintColor:tintColor tintBlendMode:kCGBlendModePlusLighter];
}

- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor tintBlendMode:(NSUInteger)tintBlendMode
{
//image must be nonzero size
if (floorf(self.size.width) * floorf(self.size.height) <= 0.0f) return self;
Expand Down Expand Up @@ -102,7 +107,7 @@ - (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)itera
if (tintColor && CGColorGetAlpha(tintColor.CGColor) > 0.0f)
{
CGContextSetFillColorWithColor(ctx, [tintColor colorWithAlphaComponent:0.25].CGColor);
CGContextSetBlendMode(ctx, kCGBlendModePlusLighter);
CGContextSetBlendMode(ctx, tintBlendMode);
CGContextFillRect(ctx, CGRectMake(0, 0, buffer1.width, buffer1.height));
}

Expand Down Expand Up @@ -135,6 +140,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;
Expand Down Expand Up @@ -280,6 +286,7 @@ - (void)setUp
if (!_blurRadiusSet) _blurRadius = 40.0f;
if (!_dynamicSet) _dynamic = YES;
if (!_blurEnabledSet) _blurEnabled = YES;
if (!_tintBlendModeSet) _tintBlendMode = kCGBlendModePlusLighter;
self.updateInterval = _updateInterval;
self.layer.magnificationFilter = @"linear"; //kCAFilterLinear;

Expand Down Expand Up @@ -336,6 +343,14 @@ - (void)setBlurRadius:(CGFloat)blurRadius
[self setNeedsDisplay];
}

- (void)setTintBlendMode:(NSUInteger)tintBlendMode {
_tintBlendModeSet = YES;
if (_tintBlendMode != tintBlendMode) {
_tintBlendMode = tintBlendMode;
[self setNeedsDisplay];
}
}

- (void)setBlurEnabled:(BOOL)blurEnabled
{
_blurEnabledSet = YES;
Expand Down Expand Up @@ -497,7 +512,8 @@ - (UIImage *)blurredSnapshot:(UIImage *)snapshot
{
return [snapshot blurredImageWithRadius:self.blurRadius
iterations:self.iterations
tintColor:self.tintColor];
tintColor:self.tintColor
tintBlendMode:self.tintBlendMode];
}

- (void)setLayerContents:(UIImage *)image
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ This property controls the radius of the blur effect (in points). Defaults to a

This in an optional tint color to be applied to the FXBlurView. The RGB components of the color will be blended with the blurred image, resulting in a gentle tint. To vary the intensity of the tint effect, use brighter or darker colors. The alpha component of the tintColor is ignored. If you do not wish to apply a tint, set this value to nil or [UIColor clearColor]. Note that if you are using Xcode 5 or above, FXBlurViews created in Interface Builder will have a blue tint by default.

@property (nonatomic, assign) NSUInteger tintBlendMode;

This in an optional blend mode used when applying `-tintColor`. The default value is kCGBlendModePlusLighter.

@property (nonatomic, weak) UIView *underlyingView;

This property specifies the view that the FXBlurView will sample to create the blur effect. If set to nil (the default), this will be the superview of the blur view itself, but you can override this if you need to.
Expand Down