Created
December 15, 2010 16:38
-
-
Save marshluca/742219 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
#import <UIKit/UIKit.h> | |
#import <Foundation/Foundation.h> | |
/*@protocol MActivityIndicatorProtocol | |
- (void)handleTask:(SEL)task; | |
- (void)hideIndicator; | |
@end*/ | |
@interface MActivityIndicator : UIView { | |
BOOL shown; | |
UIWindow *_window; | |
UILabel *textLabel; | |
UIActivityIndicatorView *indicatorView; | |
} | |
@property (nonatomic, retain) UILabel *textLabel; | |
@property (nonatomic, retain) UIActivityIndicatorView *indicatorView; | |
- (id)initWithWindow:(UIWindow *)aWindow; | |
- (void)loadTextLabel; | |
- (void)loadIndicatorView; | |
- (void)showIndicator; | |
- (void)hideIndicator; | |
@end |
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
#import "MActivityIndicator.h" | |
#import <QuartzCore/QuartzCore.h> | |
#define WIDTH 80 | |
#define HEIGHT 80 | |
@implementation MActivityIndicator | |
@synthesize textLabel,indicatorView; | |
- (id)initWithWindow:(UIWindow *)aWindow | |
{ | |
self = [super initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)]; | |
if (self) | |
{ | |
shown = NO; | |
_window = aWindow; | |
self.center = CGPointMake(_window.bounds.size.width / 2, _window.bounds.size.height / 2); | |
self.clipsToBounds = YES; | |
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.9]; | |
self.alpha = 0.7; | |
self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | | |
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; | |
if ([self.layer respondsToSelector:@selector(setCornerRadius:)]) { | |
[(id) self.layer setCornerRadius:10]; | |
} | |
[self loadTextLabel]; | |
[self loadIndicatorView]; | |
[self showIndicator]; | |
} | |
return self; | |
} | |
- (void)loadTextLabel | |
{ | |
textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT/2)]; | |
textLabel.textColor = [UIColor whiteColor]; | |
textLabel.textAlignment = UITextAlignmentCenter; | |
textLabel.backgroundColor = [UIColor clearColor]; | |
textLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; | |
[self addSubview: textLabel]; | |
} | |
- (void)loadIndicatorView | |
{ | |
indicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; | |
indicatorView.center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); | |
[indicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge]; | |
[indicatorView startAnimating]; | |
[self addSubview:indicatorView]; | |
} | |
-(void) showIndicator | |
{ | |
if (!shown) | |
{ | |
shown = YES; | |
[_window addSubview:self]; | |
} | |
} | |
-(void) hideIndicator | |
{ | |
if (shown) | |
{ | |
shown = NO; | |
[self removeFromSuperview]; | |
} | |
} | |
/* | |
-(void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
[self hide]; | |
} | |
*/ | |
- (void)dealloc | |
{ | |
[_window release]; | |
[indicatorView release]; | |
[textLabel release]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment