In your class.h file interface:
SCLAlertView *hud;
NSString *hudTitle;
NSString *hudText;
In your class.m file provide these methods:
-(void)startHud {
[self.view endEditing:YES]; //make sure keyboard is down
hud = [[SCLAlertView alloc] init];
[hud setShowAnimationType:SlideInToCenter];
hud.backgroundType = Blur;
hud.customViewColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.7f]; //set custom color
[hud setHideAnimationType:SlideOutFromCenter];
[hud showWaiting:self title:hudTitle
subTitle:hudText
closeButtonTitle:nil duration:0];
}
-(void)stopHud {
[hud setHideAnimationType:SlideOutToCenter];
hudText = @"";
hudText = @"";
[hud hideView];
}
Now wherever you want to invoke the spinner simply:
hudTitle = NSLocalizedString(@"Processing Authorization", nil);
hudText = NSLocalizedString(@"Communicating with host...", nil);
[self startHud];
Wherever you want to hide the spinner:
[self stopHud];
Taking this a step further combining with SCAlerts:
[alert addButton:NSLocalizedString(@"Authorization", nil) actionBlock:^{
hudTitle = NSLocalizedString(@"Processing Authorization", nil);
hudText = NSLocalizedString(@"Communicating with host...", nil);
[self saveObject]; //invoke some method
return;
}];
[alert addButton:NSLocalizedString(@"Update Application", nil) actionBlock:^{
hudTitle = NSLocalizedString(@"Update Application", nil);
hudText = NSLocalizedString(@"Communicating with host...", nil);
[self updateObject]; //invoke some other method
return;
}];
in your method (saveObject);
-(void)saveObject {
[self startHud];
// do something
[self stopHud];
}