Creating a "loading..." view using iPhone SDK

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

I think the simplest (a few lines of code), fully documented and most beautiful way is to use the UIAlertView with a UIActivityIndicatorView:

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

UIAlertView with UIActivityIndicatorView
(source: iosdevelopertips.com)


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.


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.