Add UIActivityIndicatorView to UINavigationBar

For me it took sometime to figure out how to show activity indicator in the navigation bar. Later I found it was very simple. When you push a view to the navigation you get to play with navigationItem property on the view that is being pushed. In your viewWillAppear method you can add this code.

	[super viewWillAppear:YES];

	UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];

	[activityIndicator stopAnimating];
	[activityIndicator hidesWhenStopped];

	UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];

	[self navigationItem].rightBarButtonItem = barButton;

	[activityIndicator release];
	[barButton release];

I have done a sample application demonstrating this code. It is based on iPhone navigation project template. In the application I have two action to start and stop the animation.


	[(UIActivityIndicatorView *)[self navigationItem].rightBarButtonItem.customView startAnimating];


	[(UIActivityIndicatorView *)[self navigationItem].rightBarButtonItem.customView stopAnimating];

Screen shot of the application

Activity indicator on navigation bar

Download Load Activity Indicator Xcode project files.

By Imthiaz

Programmer, SAAS, CMS & CRM framework designer, Love Linux & Apple products, Currently addicted to mobile development & working @bluebeetle


  1. How would I START the animation before I “visit the web to get some data” and then STOP the animation after the data is received?

    “Demo code is great”… but “real world use examples” are even better.

    (There aren’t too many people that just need 2 buttons to manually start/stop the animation.)

Comments are closed.