UIButtonBarItem 内的 UIActivityIndi​​catorView 无法正常工作

发布于 2024-08-17 01:49:07 字数 599 浏览 11 评论 0原文

我试图使用以下代码让 UIActivityIndi​​catorView 在 UIButtonBarItem 内部工作:

- (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];
}

它可以工作到显示活动指示器,但它不在按钮栏中。

有人对我在这里做错了什么有任何想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋叶绚丽 2024-08-24 01:49:07

当我希望活动指示器出现在工具栏的左侧时,我就是这样做的:

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];

然后,在我的代码中,当我想要显示活动指示器时,我只需在正常情况下使用它即可way:

[activityIndicator startAnimating];

而且,当我不想再看到它时:

[activityIndicator stopAnimating];

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];
八巷 2024-08-24 01:49:07

但它不在按钮栏中

,它在哪里?

也许您设置的框架不正确?您是否尝试过CGRectZero或随机的东西(例如CGRectMake(40,60,20,20))?对指标的位置有影响吗?

您是否尝试过设置项目的 width 属性?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文