Skip to content

Instantly share code, notes, and snippets.

@g761007
Last active August 22, 2018 03:37
Show Gist options
  • Save g761007/8c94b1d9c5886ff3cfa93da698292a12 to your computer and use it in GitHub Desktop.
Save g761007/8c94b1d9c5886ff3cfa93da698292a12 to your computer and use it in GitHub Desktop.
The UIVisualEffectView extension for customized blurRadius.
//
// UIVisualEffectView+BlurRadius.h
// Created by Daniel Hsieh on 2018/8/22.
//
#import <UIKit/UIKit.h>
@interface UIVisualEffectView (BlurRadius)
@property (nonatomic) CGFloat blurRadius;
@end
//
// 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