-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMBlurView.m
81 lines (68 loc) · 2.17 KB
/
AMBlurView.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
72
73
74
75
76
77
78
79
80
81
//
// AMBlurView.m
// blur
//
// Created by Cesar Pinto Castillo on 7/1/13.
// Copyright (c) 2013 Arctic Minds Inc. All rights reserved.
//
#import "AMBlurView.h"
#import <QuartzCore/QuartzCore.h>
@interface AMBlurView ()
@property (nonatomic, strong) UIToolbar *toolBar;
@property (nonatomic, strong) CALayer *blurLayer;
@end
@implementation AMBlurView
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (id)init
{
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
[self setToolBar:[[UIToolbar alloc] initWithFrame:[self bounds]]];
[self setBlurLayer:[[self toolBar] layer]];
UIView *blurView = [UIView new];
[blurView setUserInteractionEnabled:NO];
[blurView.layer addSublayer:[self blurLayer]];
[blurView setTranslatesAutoresizingMaskIntoConstraints:NO];
[blurView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self addSubview:blurView];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[blurView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(blurView)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(-1)-[blurView]-(-1)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(blurView)]];
[self setBackgroundColor:[UIColor clearColor]];
} else {
self.alpha = 0.99;
self.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.8];
}
}
- (void) setBlurTintColor:(UIColor *)blurTintColor {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
[self.toolBar setBarTintColor:blurTintColor];
} else {
self.backgroundColor = blurTintColor;
}
}
- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
[self.blurLayer setFrame:[self bounds]];
}
@end