-
Notifications
You must be signed in to change notification settings - Fork 1
/
TLModalActivityIndicatorView.m
95 lines (73 loc) · 2.88 KB
/
TLModalActivityIndicatorView.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// TLModalActivityIndicatorView.m
// TLCommon
//
// Created by Joshua Bleecher Snyder on 9/10/09.
//
#import "TLModalActivityIndicatorView.h"
#import "CGGeometry_TLCommon.h"
#define kModalSize 160.0f
#define kCornerRadius 20.0f
#define kLabelHeight 30.0f
#define kLabelFont [UIFont fontWithName:@"Helvetica" size:18.0f]
#define kModalColor [UIColor colorWithWhite:0.3 alpha:0.8]
#define kStartingScale 1.8f
#define kAnimationDuration 0.25f
#pragma mark -
@interface TLModalActivityIndicatorView ()
@property(nonatomic, retain, readwrite) UIActivityIndicatorView *spinner;
@end
#pragma mark -
@implementation TLModalActivityIndicatorView
@synthesize spinner;
- (id)initWithText:(NSString *)text {
if(self = [super initWithFrame:CGRectZero]) {
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
CGSize keyWindowSize = keyWindow.bounds.size;
CGPoint keyWindowCenter = CGPointMake(keyWindowSize.width / 2.0f, keyWindowSize.height / 2.0f);
self.frame = CGRectZeroWithSize(keyWindowSize);
self.backgroundColor = [UIColor clearColor];
CALayer *backgroundLayer = [CALayer layer];
backgroundLayer.cornerRadius = kCornerRadius;
backgroundLayer.masksToBounds = YES;
backgroundLayer.bounds = CGRectMake(0.0f, 0.0f, kModalSize, kModalSize);
backgroundLayer.position = keyWindowCenter;
backgroundLayer.backgroundColor = kModalColor.CGColor;
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(keyWindowCenter.x - kModalSize / 2.0f,
keyWindowCenter.y + kModalSize / 2.0f - kLabelHeight,
kModalSize,
kLabelHeight)]
autorelease];
label.text = text;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
label.font = kLabelFont;
label.textAlignment = UITextAlignmentCenter;
self.spinner = [[[UIActivityIndicatorView alloc] initWithFrame:CGRectZero] autorelease];
self.spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[self.spinner sizeToFit];
[self.spinner startAnimating];
self.spinner.center = keyWindowCenter;
[self.layer addSublayer:backgroundLayer];
[self addSubview:label];
[self addSubview:self.spinner];
self.transform = CGAffineTransformMakeScale(kStartingScale, kStartingScale);
}
return self;
}
- (void)show {
[[UIApplication sharedApplication].keyWindow addSubview:self];
[UIView beginAnimations:@"modalSpinner" context:NULL];
self.transform = CGAffineTransformIdentity;
[UIView setAnimationDuration:kAnimationDuration];
[UIView commitAnimations];
}
- (void)dismiss {
[self removeFromSuperview];
}
- (void)dealloc {
[spinner release];
spinner = nil;
[super dealloc];
}
@end