Created
September 17, 2010 12:43
-
-
Save marshluca/584172 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define activityViewTag 0x98751234 | |
@interface UIView (UIViewUtils) | |
- (void)showActivityViewAtCenter; | |
- (void)hideActivityViewAtCenter; | |
- (UIActivityIndicatorView*)createActivityViewAtCenter:(UIActivityIndicatorViewStyle)style; | |
- (UIActivityIndicatorView*)getActivityViewAtCenter; | |
@end | |
#import "UIViewUtils.h" | |
@implementation UIView (UIViewUtils) | |
- (UIActivityIndicatorView*)createActivityViewAtCenter:(UIActivityIndicatorViewStyle)style | |
{ | |
static int size = 30; | |
UIActivityIndicatorView* activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:style]; | |
activityView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2 - size/2, [UIScreen mainScreen].bounds.size.height/2 - size*2, size, size); | |
activityView.tag = activityViewTag; | |
[self addSubview:activityView]; | |
[activityView release]; | |
return activityView; | |
} | |
- (UIActivityIndicatorView*)getActivityViewAtCenter | |
{ | |
UIView* view = [self viewWithTag:activityViewTag]; | |
if (view != nil && [view isKindOfClass:[UIActivityIndicatorView class]]){ | |
return (UIActivityIndicatorView*)view; | |
} | |
else { | |
return nil; | |
} | |
} | |
- (void)showActivityViewAtCenter | |
{ | |
UIActivityIndicatorView* activityView = [self getActivityViewAtCenter]; | |
if (activityView == nil){ | |
activityView = [self createActivityViewAtCenter:UIActivityIndicatorViewStyleWhite]; | |
} | |
[activityView startAnimating]; | |
} | |
- (void)hideActivityViewAtCenter | |
{ | |
UIActivityIndicatorView* activityView = [self getActivityViewAtCenter]; | |
if (activityView != nil){ | |
[activityView stopAnimating]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment