Breaking News
Home / iOS / iOS Snippets / How to add Activity Indicator to UIToolbar in iOS?

How to add Activity Indicator to UIToolbar in iOS?

Answer

The UIToolBar uses UIBartButtonItems for adding buttons. The key here is to create a UIBarButtonItem with the UIActivityIndicatorView as a custom view. Then add that button to say right side of toolbar. Rest invoke startAnimating on the activity indicator to display the activity indicator rotating circle, do the task and invoke stop when done.

Snippet

  1.     UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
  2.  
  3.     [activityIndicator startAnimating];
  4.  
  5.     UIBarButtonItem *activityItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
  6.  
  7.      self.navigationItem.rightBarButtonItem = activityItem;
  8.  
  9.     [activityItem release];
  10.  
  11.     do the task —–
  12.  
  13.    [activityIndicator stopAnimating];
[pb_builder]

Check Also

EKCalendar – That account does not allow calendars to be added or removed

Usecase When I am trying to create a new Calendar programmatically using the EventKit API …

Advertisment ad adsense adlogger