Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using SCLAlert as HUD #106

Closed
rjpalermo1 opened this issue Apr 20, 2015 · 1 comment
Closed

Using SCLAlert as HUD #106

rjpalermo1 opened this issue Apr 20, 2015 · 1 comment

Comments

@rjpalermo1
Copy link

Noodled around a bit and found an easy way to use this great control as a custom HUD / spinner replacement:

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];
}

@dogo
Copy link
Owner

dogo commented Apr 22, 2015

Nice

@dogo dogo closed this as completed Apr 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants