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

Tint color options #101

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
3 changes: 2 additions & 1 deletion FXBlurView/FXBlurView.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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

Expand All @@ -68,6 +68,7 @@
@property (nonatomic, assign) NSTimeInterval updateInterval;
@property (nonatomic, assign) CGFloat blurRadius;
@property (nonatomic, strong) UIColor *tintColor;
@property (nonatomic) CGBlendMode tintBlendMode;
@property (nonatomic, weak_ref) IBOutlet UIView *underlyingView;

- (void)updateAsynchronously:(BOOL)async completion:(void (^)())completion;
Expand Down
21 changes: 15 additions & 6 deletions FXBlurView/FXBlurView.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

@implementation 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
{
//image must be nonzero size
if (floorf(self.size.width) * floorf(self.size.height) <= 0.0f) return self;
Expand Down Expand Up @@ -99,8 +99,14 @@ - (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);
CGFloat tintAlpha = CGColorGetAlpha(tintColor.CGColor);

if (tintAlpha == 1.0f) {
tintAlpha = 0.25f;
}

CGContextSetFillColorWithColor(ctx, [tintColor colorWithAlphaComponent:CGColorGetAlpha(tintColor.CGColor)].CGColor);
CGContextSetBlendMode(ctx, tintBlendMode);
CGContextFillRect(ctx, CGRectMake(0, 0, buffer1.width, buffer1.height));
}

Expand Down Expand Up @@ -156,6 +162,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 @@ -265,7 +272,7 @@ - (void)updateAsynchronously
}
}
}

//try again, delaying until the time when the next view needs an update.
self.viewIndex = 0;
[self performSelector:@selector(updateAsynchronously)
Expand Down Expand Up @@ -306,6 +313,7 @@ - (void)setUp
if (!_blurRadiusSet) [self blurLayer].blurRadius = 40;
if (!_dynamicSet) _dynamic = YES;
if (!_blurEnabledSet) _blurEnabled = YES;
if (!_tintBlendModeSet) _tintBlendMode = kCGBlendModePlusLighter;
self.updateInterval = _updateInterval;
self.layer.magnificationFilter = @"linear"; // kCAFilterLinear

Expand Down Expand Up @@ -482,7 +490,7 @@ - (void)displayLayer:(__unused CALayer *)layer
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:key];
animation.fromValue = [layer.presentationLayer valueForKey:key];

//CAMediatiming attributes
animation.beginTime = action.beginTime;
animation.duration = action.duration;
Expand Down Expand Up @@ -581,7 +589,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
Expand Down