我有一个UITableView从Parse.com获取它的数据。虽然它正在这样做,我想在桌子上方显示一个活动指示器。我的代码是:
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.center=self.view.center;
[self.view addSubview:indicator];
[indicator startAnimating];
然而,它不是很重要:
抱歉这张照片很棒!我尝试将指标添加到表superView,它没有什么区别。这一切都是菜鸟的一点点。有人可以给我一些指示我可能做错的事吗?
答案 0 :(得分:5)
不,不。你不需要任何这些。您需要做的就是:
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
想要关闭它后,请执行以下操作:
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
不要担心将指标添加为子视图或其位置或大小。它是状态栏的一部分,Apple负责处理它,你不能改变它的大小/颜色等等。你可以打开和关闭它。
<强>更新强>
哦对不起,我以为你在谈论UIStatusBar活动指标。在回答您的问题时,为了使UIActivityIndicatorView居中,请执行以下操作:
UIActivityIndicatorView *spinner = [[UIActivityIndicatorVIew alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
CGRect frame = spinner.frame;
frame.origin.x = (self.view.frame.size.width / 2 - frame.size.width / 2);
frame.origin.y = (self.view.frame.size.height / 2 - frame.size.height / 2);
spinner.frame = frame;
[view addSubview:spinner];
[spinner startAnimating];
答案 1 :(得分:1)
您可以使用UITableview的背景视图来显示ActivityIndicator。
lazy var activityIndicatorBase : UIActivityIndicatorView = {
let activityIndicator = UIActivityIndicatorView()
activityIndicator.frame = CGRect(x:0.0, y:0.0, width:60.0, height:60.0);
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = .gray
activityIndicator.color = UIColor.orange
activityIndicator.startAnimating()
return activityIndicator
}()
显示指标
self.tblMessage.backgroundView = self.activityIndicatorBase
隐藏指标
self.tblMessage.backgroundView = nil
答案 2 :(得分:-1)
试试这个。!
UIActivityIndicatorView * indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.frame = CGRectMake(65, 20, indicator.bounds.size.width, indicator.bounds.size.height);
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;
[self.view addSubview:indicator];
[indicator startAnimating];