Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 85 lines (67 sloc) 2.787 kb
7abebfb @soffes Add SSSimplePullToRefreshContentView
soffes authored
1 //
2747cdd @soffes Add simple content view
soffes authored
2 // SSPullToRefreshDefaultContentView
7abebfb @soffes Add SSSimplePullToRefreshContentView
soffes authored
3 // SSPullToRefresh
4 //
5 // Created by Sam Soffes on 4/9/12.
6 // Copyright (c) 2012 Sam Soffes. All rights reserved.
7 //
8
2747cdd @soffes Add simple content view
soffes authored
9 #import "SSPullToRefreshDefaultContentView.h"
7abebfb @soffes Add SSSimplePullToRefreshContentView
soffes authored
10
2747cdd @soffes Add simple content view
soffes authored
11 @implementation SSPullToRefreshDefaultContentView
7abebfb @soffes Add SSSimplePullToRefreshContentView
soffes authored
12
13 @synthesize statusLabel = _statusLabel;
14 @synthesize lastUpdatedAtLabel = _lastUpdatedAtLabel;
15 @synthesize activityIndicatorView = _activityIndicatorView;
16
17 #pragma mark - UIView
18
19 - (id)initWithFrame:(CGRect)frame {
20 if ((self = [super initWithFrame:frame])) {
21 CGFloat width = self.bounds.size.width;
22
aa17e00 @soffes Update label positioning
soffes authored
23 _statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 14.0f, width, 20.0f)];
7abebfb @soffes Add SSSimplePullToRefreshContentView
soffes authored
24 _statusLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
25 _statusLabel.font = [UIFont boldSystemFontOfSize:14.0f];
26 _statusLabel.textColor = [UIColor blackColor];
27 _statusLabel.backgroundColor = [UIColor clearColor];
28 _statusLabel.textAlignment = UITextAlignmentCenter;
29 [self addSubview:_statusLabel];
30
aa17e00 @soffes Update label positioning
soffes authored
31 _lastUpdatedAtLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 34.0f, width, 20.0f)];
7abebfb @soffes Add SSSimplePullToRefreshContentView
soffes authored
32 _lastUpdatedAtLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
33 _lastUpdatedAtLabel.font = [UIFont systemFontOfSize:12.0f];
34 _lastUpdatedAtLabel.textColor = [UIColor lightGrayColor];
35 _lastUpdatedAtLabel.backgroundColor = [UIColor clearColor];
36 _lastUpdatedAtLabel.textAlignment = UITextAlignmentCenter;
37 [self addSubview:_lastUpdatedAtLabel];
38
39 _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
aa17e00 @soffes Update label positioning
soffes authored
40 _activityIndicatorView.frame = CGRectMake(30.0f, 25.0f, 20.0f, 20.0f);
7abebfb @soffes Add SSSimplePullToRefreshContentView
soffes authored
41 [self addSubview:_activityIndicatorView];
42 }
43 return self;
44 }
45
46
47 #pragma mark - SSPullToRefreshContentView
48
49 - (void)setState:(SSPullToRefreshViewState)state withPullToRefreshView:(SSPullToRefreshView *)view {
50 switch (state) {
51 case SSPullToRefreshViewStateReady: {
52 _statusLabel.text = @"Release to refresh...";
53 [_activityIndicatorView stopAnimating];
54 break;
55 }
56
57 case SSPullToRefreshViewStateNormal: {
58 _statusLabel.text = @"Pull down to refresh...";
59 [_activityIndicatorView stopAnimating];
60 break;
61 }
de38c53 @soffes Add closing state
soffes authored
62
63 case SSPullToRefreshViewStateLoading:
64 case SSPullToRefreshViewStateClosing: {
7abebfb @soffes Add SSSimplePullToRefreshContentView
soffes authored
65 _statusLabel.text = @"Loading...";
66 [_activityIndicatorView startAnimating];
67 break;
68 }
69 }
70 }
71
72
73 - (void)setLastUpdatedAt:(NSDate *)date withPullToRefreshView:(SSPullToRefreshView *)view {
74 static NSDateFormatter *dateFormatter = nil;
75 static dispatch_once_t onceToken;
76 dispatch_once(&onceToken, ^{
77 dateFormatter = [[NSDateFormatter alloc] init];
78 dateFormatter.dateStyle = NSDateFormatterLongStyle;
79
80 });
81 _lastUpdatedAtLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [dateFormatter stringFromDate:date]];
82 }
83
84 @end
Something went wrong with that request. Please try again.