
The private API UIProgressHUD shows an activity indicator (spinner) over a shaded round rect. Although you can use fancy and flexible replacements like MBProgressHUD, there is a simpler way if you don’t need all the extra functionality: Take a regular UIActivityIndicatorView and add a partly transparent UIView behind it.
The simplest is to subclass of UIActivityIndicatorView so you can use it like any activity indicator.
The interface file:
// ActivityHUD.h #import@interface ActivityHUD : UIActivityIndicatorView - (ActivityHUD *)initInView:(UIView *)view; @end
And the implementation file:
// ActivityHUD.m #import "ActivityHUD.h" #import@implementation ActivityHUD - (ActivityHUD *)initInView:(UIView *)view { self = [super initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; if (self) { // add background view CGFloat border = self.bounds.size.height / 2; CGRect hudFrame = CGRectInset(self.bounds, -border, -border); UIView *hud = [[UIView alloc] initWithFrame:hudFrame]; hud.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.67]; hud.layer.cornerRadius = border; [self addSubview:hud]; [self sendSubviewToBack:hud]; // center in parent view [view addSubview:self]; self.center = [self convertPoint:view.center fromView:view]; } return self; } @end
To use, init the ActivityHUD in a view, and later call startAnimating to show it, and stopAnimating to hide.
Some actions may sometimes have more than one possible target, and other times only one.
Or picking an image. If you’re running on a camera-less iPod, you just show a UIImagePickerController to pick from the photo library. But with a camera, and maybe an existing image to delete, you’ll want to show an action sheet to choose the actual action that your “Photo” button performs.
I like the simple and straightforward interface of the Reminders.app: edit reminders inline, and add a reminder by tapping and typing in the next empty line. So I wrote a UITableViewController subclass that does just that, but adds Edit mode with reordering.