react-native-blur/ios/BlurView.m

49 lines
1.4 KiB
Mathematica
Raw Normal View History

#import <UIKit/UIKit.h>
#import "BlurView.h"
2016-12-21 11:31:08 +00:00
#import "BlurAmount.h"
@interface BlurView ()
@property (nonatomic, strong) UIVisualEffectView *visualEffectView;
@property (nonatomic, strong) UIBlurEffect *blurEffect;
@end
@implementation BlurView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
self.visualEffectView = [[UIVisualEffectView alloc] initWithEffect:self.blurEffect];
self.visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.visualEffectView.frame = frame;
self.clipsToBounds = true;
[self addSubview:self.visualEffectView];
}
return self;
}
- (void)setBlurType:(NSString *)blurType
{
if ([blurType isEqual: @"xlight"]) {
self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
} else if ([blurType isEqual: @"light"]) {
self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
} else if ([blurType isEqual: @"dark"]) {
self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
} else {
self.blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
}
self.visualEffectView.effect = self.blurEffect;
}
- (void)setBlurAmount:(NSNumber *)blurAmount
{
[BlurAmount updateBlurAmount:blurAmount];
}
@end