Skip to content

Instantly share code, notes, and snippets.

@ppworks
Created July 6, 2012 04:56
Show Gist options
  • Save ppworks/3058199 to your computer and use it in GitHub Desktop.
Save ppworks/3058199 to your computer and use it in GitHub Desktop.
UIUtilitiy
#import <Foundation/Foundation.h>
@interface UIUtilitiy : NSObject
+ (void)showAlert: (NSString*)title text:(NSString*)text;
+ (void)showActivityIndicator:(UIViewController *)controller;
+ (void)hideActivityIndicator;
@end
#import "UIUtilitiy.h"
#import "AppDelegate.h"
@implementation UIUtilitiy
static UIView *_indicatorView = nil;
+ (void)showAlert: (NSString*)title text:(NSString*)text {
UIAlertView* alert = [[[UIAlertView alloc]
initWithTitle:title message:text delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
[alert show];
}
+ (void)showActivityIndicator:(UIViewController *) controller {
if (!_indicatorView) {
_indicatorView = [[UIView alloc]init];
_indicatorView.backgroundColor = [UIColor colorWithHue:0
saturation:1.0
brightness:0.0
alpha:0.1];
_indicatorView.frame = CGRectMake(0, 0, 320.0, 480.0);
UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]autorelease];
activityIndicator.frame = CGRectMake(130.0, 180.0, 60.0, 60.0);
activityIndicator.hidden = NO;
[activityIndicator startAnimating];
[_indicatorView addSubview:activityIndicator];
}
[_indicatorView removeFromSuperview];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[controller.view addSubview:_indicatorView];
[controller.view bringSubviewToFront:_indicatorView];
}
+ (void)hideActivityIndicator {
[_indicatorView removeFromSuperview];
[_indicatorView release], _indicatorView = nil;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment