Last active
August 22, 2018 03:37
-
-
Save g761007/8c94b1d9c5886ff3cfa93da698292a12 to your computer and use it in GitHub Desktop.
The UIVisualEffectView extension for customized blurRadius.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIVisualEffectView+BlurRadius.h | |
// Created by Daniel Hsieh on 2018/8/22. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIVisualEffectView (BlurRadius) | |
@property (nonatomic) CGFloat blurRadius; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIVisualEffectView+BlurRadius.m | |
// Created by Daniel Hsieh on 2018/8/22. | |
// | |
#import "UIVisualEffectView+BlurRadius.h" | |
@implementation UIVisualEffectView (BlurRadius) | |
- (void)setBlurRadius:(CGFloat)blurRadius { | |
objc_setAssociatedObject(self, @selector(blurRadius), @(blurRadius), OBJC_ASSOCIATION_ASSIGN); | |
if (@available(iOS 9.0, *)) { | |
UIBlurEffect *effect = [NSClassFromString(@"_UICustomBlurEffect") new]; | |
[effect setValue:@(blurRadius) forKeyPath:@"blurRadius"]; | |
self.effect = effect; | |
} else { | |
NSLog(@"Minimum OS requirement for iOS 9.0 or later."); | |
} | |
} | |
- (CGFloat)blurRadius { | |
return [objc_getAssociatedObject(self, _cmd) floatValue]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment