views:

5535

answers:

5

How to create that black/gray modal popup kind of view that many apps use, when some long pending operation is in progress?

Like when using location based services, loading a webpage, the screen goes dim and there is a modal view showing a spinning icon "Please wait..."

I've posted a screenshot of what I mean here... http://www.flickr.com/photos/mugunthkumar/3503268688/

+13  A: 

This is actually the undocumented (in 2.2.1 anyway) UIProgressHUD. Create one like this:

In your .h:

@interface UIProgressHUD : NSObject 
- (UIProgressHUD *) initWithWindow: (UIView*)aWindow; 
- (void) show: (BOOL)aShow; 
- (void) setText: (NSString*)aText; 
@end

In your .m:

- (void) killHUD: (id)aHUD 
{ 
[aHUD show:NO]; 
[aHUD release]; 
} 

- (void) presentSheet 
{ 
id HUD = [[UIProgressHUD alloc] initWithWindow:[contentView superview]]; 
[HUD setText:@"Doing something slow. Please wait."]; 
[HUD show:YES]; 
[self performSelector:@selector(killHUD:) withObject:HUD afterDelay:5.0]; 
}
Jane Sales
Can this be used and submitted to the App Store?
John Fricker
Yes, this is not linking to private API. We’ve done something similar with buttons on the UIAlertView, went through review with no problems.
zoul
I didn't know that - thanks zoul.
Jane Sales
+3  A: 

If you add a UIView as a subview of the main window it will cover the entire UI. Make it partially transparent and partially translucent and it will look like a popup.

This example shows how to fade the Default.png splash screen, starting with that it's pretty straightforward to add a couple methods to your application delegate (that has a pointer to the main window) to present and dismiss the progress view.

duncanwilcox
Hi duncanwilcox, I wanted this also... fading default.png screen... :) Thanks... You seems to answer questions which I still have not asked... :D
Mugunth Kumar
+3  A: 

Take a look at the Wordpress iPhone app (http://iphone.wordpress.org/) for an example of how to do this without using any undocumented API's.

Lounges
+2  A: 

If you want to avoid undocumented api you can also take a look at MBProgressHUD. It's similar to UIProgressHUD and even has some additional features.

Matej Bukovinski
URL gives a 404?
Jane Sales
Sorry for that. Get it at http://github.com/matej/MBProgressHUD
Matej Bukovinski