如何将 UIActivityIndicatorView 微调器圈添加到 UIBarButton 中,以便当用户点击导航栏上的这些按钮之一时,他们会在加载时看到微调器?
问问题
15722 次
6 回答
49
如果您尝试在导航栏按钮中显示活动轮(例如,您的导航栏上可能有一个刷新按钮) - 您可以创建一个新UIBarButtonItem
的自定义视图UIActivityIndicatorView
:
Objective-C
uiBusy = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
uiBusy.hidesWhenStopped = YES;
[uiBusy startAnimating];
[self.navigationItem.rightBarButtonItem initWithCustomView:uiBusy];
迅速
let uiBusy = UIActivityIndicatorView(activityIndicatorStyle: .White)
uiBusy.hidesWhenStopped = true
uiBusy.startAnimating()
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: uiBusy)
rightBarButtonItem
这会用纺车覆盖你。完成后,只需重新创建rightBarButtonItem
.
于 2011-02-01T20:22:54.553 回答
6
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.hidesWhenStopped = YES;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
将以下内容放在需要的地方:
[activityIndicator startAnimating];
[activityIndicator stopAnimating];
于 2013-02-21T08:00:34.700 回答
2
实际上活动指示器没有添加为工具栏项。这是当前视图的子视图。
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[act setCenter:CGPointMake(20, 20)];
[act startAnimating];
[self.view addSubview:act];
记得在-(void)dealloc
.
于 2009-11-12T07:59:14.823 回答
0
使用此方法
-(void)startAniatingActivityIndicator{
@try {
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.frame = CGRectMake(self.window.frame.size.width-30, 32.5, activityIndicator.bounds.size.width, activityIndicator.bounds.size.height);
[self.window addSubview:activityIndicator];
[activityIndicator startAnimating];
[self.window bringSubviewToFront:activityIndicator];
}
@catch (NSException *exception) {
}
@finally {
}
}
-(void)stopAniatingActivityIndicator{
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}
于 2014-04-26T05:54:32.623 回答
-1
UIActivityIndicatorView 是一种视图。将其框架设置在您的按钮内,并使用 -addSubview 将其添加到 UIBarButton 的视图层次结构中。
我过于简单化了,因为您必须尝试使其适合空间(可能通过缩放)并将其居中...
于 2009-11-12T05:38:20.083 回答
-2
伪代码,我不打算在 Xcode 中检查这个,但是这样的东西应该可以工作:
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] init];
act.frame = CGMakeRect(3,3,25,25);
[myBarButton addSubview:act];
[act release];
于 2009-11-12T05:41:49.563 回答