views:

1129

answers:

3

How do I add a UIActivityIndicatorView spinner circle into a UIBarButton? So that when a user taps on one of those buttons on the navigation bar, they see a spinner while the loading takes place?

Thanks.

A: 

UIActivityIndicatorView is a type of view. Set its frame to be within your button and use -addSubview to add it to the view hierarchy of the UIBarButton.

I'm oversimplifying, since you have to try to make it fit the space (possibly by scaling) and center it...

mahboudz
A: 

pseudocode, i'm not going to check this in Xcode, but something like this should work:

UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] init];
act.frame = CGMakeRect(3,3,25,25);
[myBarButton addSubview:act];
[act release];
Kenny Winker
`UIBarButtonItem` isn't a `UIView` subclass and doesn't have `addSubview:`. You should do something like `UIBarButtonItem *myBarButton = [[UIBarButtonItem alloc] initWithCustomView:act];` instead or `myBarButton.customView = act;`.
Sam Soffes
A: 

Actually activity indicator is not added as toolbar item. It's a subview of current view.


    UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    [act setCenter:CGPointMake(20, 20)];
    [act startAnimating];
    [self.view addSubview:act];

Remember to release it in -(void)dealloc.

iPhoney
More information about how to use activity indicator is here:http://stackoverflow.com/questions/593234/how-to-use-activity-indicator-view-on-iphone
iPhoney