Add UIActivityIndicatorView into UIBarButton

If you’re trying to show the activity wheel in a navigation bar button (e.g. you might have a refresh button on your navbar) – you can create a new UIBarButtonItem with a custom view being the UIActivityIndicatorView:

Objective-C

uiBusy = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
uiBusy.hidesWhenStopped = YES;
[uiBusy startAnimating];
[self.navigationItem.rightBarButtonItem initWithCustomView:uiBusy];

Swift

let uiBusy = UIActivityIndicatorView(activityIndicatorStyle: .White)
uiBusy.hidesWhenStopped = true
uiBusy.startAnimating()
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: uiBusy)

This overwrites your rightBarButtonItem with the spinning wheel. When you’re done, just recreate the rightBarButtonItem.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)