How to use a custom UIBarButtonItem to display a UIActivityIndicatorView
How to use a custom UIBarButtonItem to display a UIActivityIndicatorView
Here is a typical UIBarButtonItem created to display a refresh button in the navigation bar.
UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshLogsAction:)];
self.navigationItem.rightBarButtonItem = refreshItem;
[refreshItem release];
Here’s how to change that button to a UIActivityIndicatorView custom UIBarButtonItem button.
- (void)refreshLogsAction:(id)sender;
{
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[activityIndicator startAnimating];
UIBarButtonItem *activityItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[activityIndicator release];
self.navigationItem.rightBarButtonItem = activityItem;
[activityItem release];
... do something
}
Sunday, October 26, 2008