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

Fix for Swift and more flexible tint #72

Open
wants to merge 2 commits 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 @@ -32,7 +32,6 @@


#import <UIKit/UIKit.h>
#import <Accelerate/Accelerate.h>


#pragma GCC diagnostic push
Expand All @@ -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

Expand All @@ -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;
Expand Down
22 changes: 18 additions & 4 deletions FXBlurView/FXBlurView.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#import <objc/runtime.h>
#import <objc/message.h>
#import <QuartzCore/QuartzCore.h>
#import <Accelerate/Accelerate.h>


#pragma GCC diagnostic ignored "-Wobjc-missing-property-synthesis"
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -429,6 +436,12 @@ - (void)setTintColor:(UIColor *)tintColor
[self setNeedsDisplay];
}

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

- (void)didMoveToSuperview
{
[super didMoveToSuperview];
Expand Down Expand Up @@ -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
Expand Down