-
Notifications
You must be signed in to change notification settings - Fork 0
/
LRStatusView.m
110 lines (88 loc) · 3.35 KB
/
LRStatusView.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// LRStatusView.m
// ModalStatusOverlay
//
// Created by Ricky Hussmann on 5/6/11.
// Copyright 2011 LovelyRide. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "LRStatusView.h"
UIView* createBackgroundViewForFrame(CGRect frame) {
CGRect bgRect = CGRectMake(0,
0,
frame.size.width,
frame.size.height);
UIView *background = [[[UIView alloc] initWithFrame:bgRect] autorelease];
background.backgroundColor = [UIColor blackColor];
background.alpha = 0.2;
background.layer.cornerRadius = 7;
return background;
}
UILabel* createStatusLabelWithTextForFrame(NSString *text, CGRect frame) {
UILabel *statusLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)] autorelease];
statusLabel.numberOfLines = 0;
statusLabel.lineBreakMode = UILineBreakModeWordWrap;
statusLabel.text = text;
[statusLabel sizeToFit];
CGFloat labelHeight = statusLabel.bounds.size.height;
CGFloat labelWidth = statusLabel.bounds.size.width;
CGRect labelRect = CGRectMake(frame.size.width/2.0 - labelWidth/2.0,
frame.size.height/2.0 - labelHeight/2.0,
labelWidth,
labelHeight);
statusLabel.frame = labelRect;
statusLabel.backgroundColor = [UIColor clearColor];
statusLabel.textColor = [UIColor whiteColor];
statusLabel.shadowColor = [UIColor blackColor];
statusLabel.shadowOffset = CGSizeMake(-1, 1);
return statusLabel;
}
@implementation LRStatusView
@synthesize _backgroundView;
@synthesize _statusLabel;
@synthesize _activityIndicator;
- (id)initWithFrame:(CGRect)frame labelText:(NSString*)text indicatorVisible:(BOOL)indicatorVisible
{
self = [super initWithFrame:frame];
if (self) {
self.clipsToBounds = YES;
self._backgroundView = createBackgroundViewForFrame(frame);
self._statusLabel = createStatusLabelWithTextForFrame(text, frame);
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
CGPoint statusLabelCenter = self._statusLabel.center;
CGRect indicatorRect = CGRectMake(statusLabelCenter.x - 20.0/2.0,
statusLabelCenter.y - self._statusLabel.frame.size.height/2.0 - 20,
20,
20);
indicator.frame = indicatorRect;
indicator.hidden = NO;
[indicator startAnimating];
self._activityIndicator = indicator;
[indicator release];
[self addSubview:self._backgroundView];
[self addSubview:self._statusLabel];
if (indicatorVisible) {
[self addSubview:self._activityIndicator];
}
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
return [self initWithFrame:frame labelText:@"Label" indicatorVisible:YES];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
- (void)dealloc
{
self._statusLabel = nil;
self._activityIndicator = nil;
[super dealloc];
}
@end