Is there an equivalent in iOS to the Android ProgressDialog [duplicate]
Asked Answered
C

1

6

In Android development, I use a ProgressDialog to give me a dialog with a 'spinny', some text and a cancel button. I use this combined with a CountdownTimer to perform an action after 10 seconds unless the user cancels the dialog.

I have searched around for an equivalent in iOS, such as the open source SVProgressHUD and MBProgressHUD but none seem to support the addition of a button.

Do I have to write my own, or does anyone know of an easy way to achieve this?

Channa answered 25/11, 2014 at 13:49 Comment(2)
since IOS 9.0 UIAlertView has been deprecated. Follow this for an updated answer!Whitt
Try this HUD library for iOS in swift github.com/shubh10/JustHUDDenishadenison
A
8
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
indicator.center = self.view.center;    
[self.view addSubview:indicator];
[indicator bringSubviewToFront:self.view];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;

Write below code when you want to show indicator

[indicator startAnimating];

write below code when you want to hide indicator

[indicator stopAnimating];

was found at How to programmatically add a simple default loading(progress) bar in iphone app

UPD: you can create alert dialog without buttons and add any custom elements manually:

UIAlertView *alert;

...

alert = [[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil]; //display without any btns
// alert = [[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil]; //to display with cancel btn
[alert show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];

To dismiss alert, just do

[alert dismissWithClickedButtonIndex:0 animated:YES];

More information at: http://iosdevelopertips.com/user-interface/uialertview-without-buttons-please-wait-dialog.html

Asuncion answered 25/11, 2014 at 13:50 Comment(7)
Thanks for the answer, but whilst this shows a spinny which I can later dismiss, it doesn't give the option of a cancel button.Channa
updated answer with new approachAsuncion
That did it, thank you, one change needed in order to show the cancel button: alert = [[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];Channa
you can mark answer as "solved my question" if it really did soAsuncion
Done, I was just editing my comment with the required amendment.Channa
Added your code snippet to answer as well.Asuncion
since IOS 9.0 UIAlertView has been deprecated. Follow this for an updated answer!Whitt

© 2022 - 2024 — McMap. All rights reserved.