forked from soffes/SSPullToRefresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSPullToRefreshSimpleContentView.m
80 lines (63 loc) · 2.36 KB
/
SSPullToRefreshSimpleContentView.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
//
// SSPullToRefreshSimpleContentView.m
// SSPullToRefresh
//
// Created by Sam Soffes on 5/17/12.
// Copyright (c) 2012 Sam Soffes. All rights reserved.
//
#import "SSPullToRefreshSimpleContentView.h"
@implementation SSPullToRefreshSimpleContentView
@synthesize statusLabel = _statusLabel;
@synthesize activityIndicatorView = _activityIndicatorView;
#pragma mark - UIView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
CGFloat width = self.bounds.size.width;
_statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 14.0f, width, 20.0f)];
_statusLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_statusLabel.font = [UIFont boldSystemFontOfSize:14.0f];
_statusLabel.textColor = [UIColor blackColor];
_statusLabel.backgroundColor = [UIColor clearColor];
_statusLabel.textAlignment = UITextAlignmentCenter;
[self addSubview:_statusLabel];
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_activityIndicatorView.frame = CGRectMake(30.0f, 25.0f, 20.0f, 20.0f);
[self addSubview:_activityIndicatorView];
}
return self;
}
- (void)layoutSubviews {
CGSize size = self.bounds.size;
self.statusLabel.frame = CGRectMake(20.0f, roundf((size.height - 30.0f) / 2.0f), size.width - 40.0f, 30.0f);
self.activityIndicatorView.frame = CGRectMake(roundf((size.width - 20.0f) / 2.0f), roundf((size.height - 20.0f) / 2.0f), 20.0f, 20.0f);
}
#pragma mark - SSPullToRefreshContentView
- (void)setState:(SSPullToRefreshViewState)state withPullToRefreshView:(SSPullToRefreshView *)view {
switch (state) {
case SSPullToRefreshViewStateReady: {
self.statusLabel.text = @"Release to refresh";
[self.activityIndicatorView startAnimating];
self.activityIndicatorView.alpha = 0.0f;
break;
}
case SSPullToRefreshViewStateNormal: {
self.statusLabel.text = @"Pull down to refresh";
self.statusLabel.alpha = 1.0f;
[self.activityIndicatorView stopAnimating];
self.activityIndicatorView.alpha = 0.0f;
break;
}
case SSPullToRefreshViewStateLoading: {
self.statusLabel.alpha = 0.0f;
[self.activityIndicatorView startAnimating];
self.activityIndicatorView.alpha = 1.0f;
break;
}
case SSPullToRefreshViewStateClosing: {
self.statusLabel.text = nil;
self.activityIndicatorView.alpha = 0.0f;
break;
}
}
}
@end