forked from soffes/SSPullToRefresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSPullToRefreshDefaultContentView.m
84 lines (67 loc) · 2.72 KB
/
SSPullToRefreshDefaultContentView.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
//
// SSPullToRefreshDefaultContentView
// SSPullToRefresh
//
// Created by Sam Soffes on 4/9/12.
// Copyright (c) 2012 Sam Soffes. All rights reserved.
//
#import "SSPullToRefreshDefaultContentView.h"
@implementation SSPullToRefreshDefaultContentView
@synthesize statusLabel = _statusLabel;
@synthesize lastUpdatedAtLabel = _lastUpdatedAtLabel;
@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];
_lastUpdatedAtLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 34.0f, width, 20.0f)];
_lastUpdatedAtLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_lastUpdatedAtLabel.font = [UIFont systemFontOfSize:12.0f];
_lastUpdatedAtLabel.textColor = [UIColor lightGrayColor];
_lastUpdatedAtLabel.backgroundColor = [UIColor clearColor];
_lastUpdatedAtLabel.textAlignment = UITextAlignmentCenter;
[self addSubview:_lastUpdatedAtLabel];
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_activityIndicatorView.frame = CGRectMake(30.0f, 25.0f, 20.0f, 20.0f);
[self addSubview:_activityIndicatorView];
}
return self;
}
#pragma mark - SSPullToRefreshContentView
- (void)setState:(SSPullToRefreshViewState)state withPullToRefreshView:(SSPullToRefreshView *)view {
switch (state) {
case SSPullToRefreshViewStateReady: {
_statusLabel.text = @"Release to refresh...";
[_activityIndicatorView stopAnimating];
break;
}
case SSPullToRefreshViewStateNormal: {
_statusLabel.text = @"Pull down to refresh...";
[_activityIndicatorView stopAnimating];
break;
}
case SSPullToRefreshViewStateLoading:
case SSPullToRefreshViewStateClosing: {
_statusLabel.text = @"Loading...";
[_activityIndicatorView startAnimating];
break;
}
}
}
- (void)setLastUpdatedAt:(NSDate *)date withPullToRefreshView:(SSPullToRefreshView *)view {
static NSDateFormatter *dateFormatter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterLongStyle;
});
_lastUpdatedAtLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [dateFormatter stringFromDate:date]];
}
@end