UIButtonBarItem 内的 UIActivityIndicatorView 无法正常工作
我试图使用以下代码让 UIActivityIndicatorView 在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我希望活动指示器出现在工具栏的左侧时,我就是这样做的:
然后,在我的代码中,当我想要显示活动指示器时,我只需在正常情况下使用它即可way:
而且,当我不想再看到它时:
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:
Then, further on in my code when I want to show the activity indicator, I simply use it in the normal way:
And, when I don't want to see it anymore:
,它在哪里?
也许您设置的框架不正确?您是否尝试过
CGRectZero
或随机的东西(例如CGRectMake(40,60,20,20)
)?对指标的位置有影响吗?您是否尝试过设置项目的
width
属性?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?