Skip to content

Instantly share code, notes, and snippets.

@benvium
Created February 27, 2013 16:16
Show Gist options
  • Select an option

  • Save benvium/5049139 to your computer and use it in GitHub Desktop.

Select an option

Save benvium/5049139 to your computer and use it in GitHub Desktop.
Animated replacement of self.navigationItem.rightBarButtonItem with an animated spinner, e.g. when network is busy. Sadly getting the layout right is hard - the width of the rightbarbuttonitem comes back as 0...
UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
spinner.hidesWhenStopped = YES;
[spinner startAnimating];
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
view.frame = CGRectMake(0, 0, 20, 30);
[view addSubview:spinner];
spinner.center = CGPointMake(width/2, 15);
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:view] animated:YES];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment