Skip to content

Commit

Permalink
Updated for 4.0 and retina display.
Browse files Browse the repository at this point in the history
  • Loading branch information
devindoty committed Sep 17, 2010
1 parent 9b825d3 commit a35b029
Show file tree
Hide file tree
Showing 20 changed files with 1,752 additions and 82 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added Demo/.DS_Store
Binary file not shown.
Binary file added Demo/TableViewPull/.DS_Store
Binary file not shown.
Expand Up @@ -36,10 +36,10 @@ typedef enum{

@interface EGORefreshTableHeaderView : UIView {

UILabel *lastUpdatedLabel;
UILabel *statusLabel;
CALayer *arrowImage;
UIActivityIndicatorView *activityView;
UILabel *_lastUpdatedLabel;
UILabel *_statusLabel;
CALayer *_arrowImage;
UIActivityIndicatorView *_activityView;

EGOPullRefreshState _state;

Expand Down
Expand Up @@ -29,7 +29,7 @@

#define TEXT_COLOR [UIColor colorWithRed:87.0/255.0 green:108.0/255.0 blue:137.0/255.0 alpha:1.0]
#define BORDER_COLOR [UIColor colorWithRed:87.0/255.0 green:108.0/255.0 blue:137.0/255.0 alpha:1.0]

#define FLIP_ANIMATION_DURATION 0.18f

@implementation EGORefreshTableHeaderView

Expand All @@ -40,70 +40,71 @@ - (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {

self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

lastUpdatedLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 30.0f, self.frame.size.width, 20.0f)];
lastUpdatedLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
lastUpdatedLabel.font = [UIFont systemFontOfSize:12.0f];
lastUpdatedLabel.textColor = TEXT_COLOR;
lastUpdatedLabel.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
lastUpdatedLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
lastUpdatedLabel.backgroundColor = [UIColor clearColor];
lastUpdatedLabel.textAlignment = UITextAlignmentCenter;
[self addSubview:lastUpdatedLabel];
[lastUpdatedLabel release];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 30.0f, self.frame.size.width, 20.0f)];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.font = [UIFont systemFontOfSize:12.0f];
label.textColor = TEXT_COLOR;
label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
label.shadowOffset = CGSizeMake(0.0f, 1.0f);
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
[self addSubview:label];
_lastUpdatedLabel=label;
[label release];

if ([[NSUserDefaults standardUserDefaults] objectForKey:@"EGORefreshTableView_LastRefresh"]) {
lastUpdatedLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"EGORefreshTableView_LastRefresh"];
_lastUpdatedLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"EGORefreshTableView_LastRefresh"];
} else {
[self setCurrentDate];
}

statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 48.0f, self.frame.size.width, 20.0f)];
statusLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
statusLabel.font = [UIFont boldSystemFontOfSize:13.0f];
statusLabel.textColor = TEXT_COLOR;
statusLabel.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
statusLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
statusLabel.backgroundColor = [UIColor clearColor];
statusLabel.textAlignment = UITextAlignmentCenter;
[self setState:EGOOPullRefreshNormal];
[self addSubview:statusLabel];
[statusLabel release];
label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 48.0f, self.frame.size.width, 20.0f)];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.font = [UIFont boldSystemFontOfSize:13.0f];
label.textColor = TEXT_COLOR;
label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
label.shadowOffset = CGSizeMake(0.0f, 1.0f);
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
[self addSubview:label];
_statusLabel=label;
[label release];

CALayer *layer = [[CALayer alloc] init];
layer.frame = CGRectMake(25.0f, frame.size.height - 65.0f, 30.0f, 55.0f);
layer.contentsGravity = kCAGravityResizeAspect;
layer.contents = (id)[UIImage imageNamed:@"blueArrow.png"].CGImage;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
layer.contentsScale = [[UIScreen mainScreen] scale];
}
#endif

[[self layer] addSublayer:layer];
_arrowImage=layer;
[layer release];

arrowImage = [[CALayer alloc] init];
arrowImage.frame = CGRectMake(25.0f, frame.size.height - 65.0f, 30.0f, 55.0f);
arrowImage.contentsGravity = kCAGravityResizeAspect;
arrowImage.contents = (id)[UIImage imageNamed:@"blueArrow.png"].CGImage;
[[self layer] addSublayer:arrowImage];
[arrowImage release];
UIActivityIndicatorView *view = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
view.frame = CGRectMake(25.0f, frame.size.height - 38.0f, 20.0f, 20.0f);
[self addSubview:view];
_activityView = view;
[view release];

activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityView.frame = CGRectMake(25.0f, frame.size.height - 38.0f, 20.0f, 20.0f);
activityView.hidesWhenStopped = YES;
[self addSubview:activityView];
[activityView release];
[self setState:EGOOPullRefreshNormal];

}
return self;
}

- (void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawPath(context, kCGPathFillStroke);
[BORDER_COLOR setStroke];
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0.0f, self.bounds.size.height - 1);
CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height - 1);
CGContextStrokePath(context);
}

- (void)setCurrentDate {
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setAMSymbol:@"AM"];
[formatter setPMSymbol:@"PM"];
[formatter setDateFormat:@"MM/dd/yyyy hh:mm:a"];
lastUpdatedLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [formatter stringFromDate:[NSDate date]]];
[[NSUserDefaults standardUserDefaults] setObject:lastUpdatedLabel.text forKey:@"EGORefreshTableView_LastRefresh"];
_lastUpdatedLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [formatter stringFromDate:[NSDate date]]];
[[NSUserDefaults standardUserDefaults] setObject:_lastUpdatedLabel.text forKey:@"EGORefreshTableView_LastRefresh"];
[[NSUserDefaults standardUserDefaults] synchronize];
[formatter release];
}
Expand All @@ -113,38 +114,38 @@ - (void)setState:(EGOPullRefreshState)aState{
switch (aState) {
case EGOOPullRefreshPulling:

statusLabel.text = @"Release to refresh...";
_statusLabel.text = NSLocalizedString(@"Release to refresh...", @"Release to refresh status");
[CATransaction begin];
[CATransaction setAnimationDuration:.18];
arrowImage.transform = CATransform3DMakeRotation((M_PI / 180.0) * 180.0f, 0.0f, 0.0f, 1.0f);
[CATransaction setAnimationDuration:FLIP_ANIMATION_DURATION];
_arrowImage.transform = CATransform3DMakeRotation((M_PI / 180.0) * 180.0f, 0.0f, 0.0f, 1.0f);
[CATransaction commit];

break;
case EGOOPullRefreshNormal:

if (_state == EGOOPullRefreshPulling) {
[CATransaction begin];
[CATransaction setAnimationDuration:.18];
arrowImage.transform = CATransform3DIdentity;
[CATransaction setAnimationDuration:FLIP_ANIMATION_DURATION];
_arrowImage.transform = CATransform3DIdentity;
[CATransaction commit];
}

statusLabel.text = @"Pull down to refresh...";
[activityView stopAnimating];
_statusLabel.text = NSLocalizedString(@"Pull down to refresh...", @"Pull down to refresh status");
[_activityView stopAnimating];
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
arrowImage.hidden = NO;
arrowImage.transform = CATransform3DIdentity;
_arrowImage.hidden = NO;
_arrowImage.transform = CATransform3DIdentity;
[CATransaction commit];

break;
case EGOOPullRefreshLoading:

statusLabel.text = @"Loading...";
[activityView startAnimating];
_statusLabel.text = NSLocalizedString(@"Loading...", @"Loading Status");
[_activityView startAnimating];
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
arrowImage.hidden = YES;
_arrowImage.hidden = YES;
[CATransaction commit];

break;
Expand All @@ -156,10 +157,10 @@ - (void)setState:(EGOPullRefreshState)aState{
}

- (void)dealloc {
activityView = nil;
statusLabel = nil;
arrowImage = nil;
lastUpdatedLabel = nil;
_activityView = nil;
_statusLabel = nil;
_arrowImage = nil;
_lastUpdatedLabel = nil;
[super dealloc];
}

Expand Down
Binary file added Demo/TableViewPull/Resources/blackArrow@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/TableViewPull/Resources/blueArrow@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/TableViewPull/Resources/grayArrow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/TableViewPull/Resources/grayArrow@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/TableViewPull/Resources/whiteArrow@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a35b029

Please sign in to comment.