Created
February 12, 2014 00:03
-
-
Save PauloMigAlmeida/8947125 to your computer and use it in GitHub Desktop.
UIView Category which hides every component inside and shows up an activityIndicator while you do things in background
This file contains 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
// | |
// UIView+LoadingWithActivityIndicator.h | |
// | |
// Created by Paulo Miguel Almeida on 2/11/14. | |
// Copyright (c) 2014 Paulo Miguel Almeida. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIView (LoadingWithActivityIndicator) | |
-(void) startLoadingAnimation; | |
-(void) stopLoadingAnimation; | |
@end |
This file contains 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
// | |
// UIView+LoadingWithActivityIndicator.m | |
// | |
// Created by Paulo Miguel Almeida on 2/11/14. | |
// Copyright (c) 2014 Paulo Miguel Almeida. All rights reserved. | |
// | |
#import "UIView+LoadingWithActivityIndicator.h" | |
@implementation UIView (LoadingWithActivityIndicator) | |
-(void) startLoadingAnimation | |
{ | |
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; | |
[activityIndicator setFrame:CGRectMake((self.frame.size.width - activityIndicator.frame.size.width) / 2 , (self.frame.size.height - activityIndicator.frame.size.height) / 2 , activityIndicator.frame.size.width , activityIndicator.frame.size.width)]; | |
for(UIView* view in self.subviews) | |
{ | |
[view setHidden:YES]; | |
} | |
[self addSubview:activityIndicator]; | |
[activityIndicator startAnimating]; | |
} | |
-(void) stopLoadingAnimation | |
{ | |
for(UIView* view in self.subviews) | |
{ | |
if([view isKindOfClass:[UIActivityIndicatorView class]]) | |
{ | |
UIActivityIndicatorView* activityIndicator = (UIActivityIndicatorView*)view; | |
[activityIndicator stopAnimating]; | |
[activityIndicator removeFromSuperview]; | |
} | |
else | |
{ | |
[view setHidden:NO]; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment