开发者

UIActivityIndicatorView inside UIButtonBarItem not working properly

I am trying to get a UIActivityIndicatorView to work inside of a UIButtonBarItem using the following code:

- (void)showActivityIndicator
{
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    [activityIndicator startAnimating];

    UIBarButtonItem *activityBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
    [activityIndicator release];

    self.navigationItem.rightBarButtonItem = activityBarButtonItem;
    [activityBarButtonItem release];
}

It works to the point that the activity indicator is displayed, but it is not inside a button bar.

Does anyone have any ideas on what im doing 开发者_运维百科wrong here?


This is what I did to get an activity indicator to appear when I wanted it to on the left-hand side of a toolbar:

activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0, 0.0, 25.0, 25.0)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
activityIndicator.hidesWhenStopped = YES;

UIBarButtonItem *btnActivity = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
NSMutableArray *tItems = [self.toolbar.items mutableCopy];
[tItems insertObject:btnActivity atIndex:0];
self.toolbar.items = tItems;
[tItems release];

Then, further on in my code when I want to show the activity indicator, I simply use it in the normal way:

[activityIndicator startAnimating];

And, when I don't want to see it anymore:

[activityIndicator stopAnimating];


but it is not inside a button bar

And where is it?

Maybe the frame you're setting is incorrect? Have you tried CGRectZero or something random (e.g. CGRectMake(40,60,20,20))? Does it have any impact on the position of the indicator?

Have you tried setting the width property of the item?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜