-
Notifications
You must be signed in to change notification settings - Fork 0
/
CTBlurredView.m
71 lines (59 loc) · 1.8 KB
/
CTBlurredView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// CTBlurredView.m
//
// Created by David Fumberger on 27/09/2013.
//
//
#import "CTBlurredView.h"
@interface CTBlurredView()
@property (nonatomic, retain) UIToolbar *_blurredToolbar;
@property (nonatomic, retain) UIView *_blurredBackgroundColorView;
@property (nonatomic, strong) UIColor *blurTintColor;
@end
@implementation CTBlurredView
+ (BOOL)supported {
return ([UIToolbar instancesRespondToSelector: @selector(barTintColor)]);
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
if ([CTBlurredView supported]) {
self._blurredToolbar = [[UIToolbar alloc] initWithFrame: self.bounds];
self._blurredToolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self insertSubview:self._blurredToolbar atIndex:0];
}
}
return self;
}
- (void)willMoveToSuperview:(UIView *)newSuperview {
[super willMoveToSuperview: newSuperview];
[self sendSubviewToBack: self._blurredToolbar];
}
- (void)layoutSubviews {
[super layoutSubviews];
[self sendSubviewToBack: self._blurredToolbar];
}
- (void)setBlurStrength:(float)strength {
_blurStrength = strength;
self._blurredToolbar.alpha = _blurStrength;
}
- (void)setBlurTintColor:(UIColor *)blurredTintColor {
_blurTintColor = [blurredTintColor colorWithAlphaComponent: 1.0f];
self._blurredToolbar.barTintColor = _blurTintColor;
}
- (void)setBackgroundColor:(UIColor *)backgroundColor {
if ([CTBlurredView supported]) {
self.blurTintColor = backgroundColor;
} else {
[super setBackgroundColor: backgroundColor];
}
}
- (UIColor*)backgroundColor {
if ([CTBlurredView supported]) {
return self.blurTintColor;
} else {
return [super backgroundColor];
}
}
@end