UIActivityIndicatorView *indicator = nil; indicator = (UIActivityIndicatorView *)[self.view viewWithTag:103]; if (indicator == nil) { //初始化: UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)]; indicator.tag = 103; //设置显示样式,见UIActivityIndicatorViewStyle的定义 indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; //设置背景色 indicator.backgroundColor = [UIColor blackColor]; //设置背景透明 indicator.alpha = 0.5; //设置背景为圆角矩形 indicator.layer.cornerRadius = 6; indicator.layer.masksToBounds = YES; //设置显示位置 [indicator setCenter:CGPointMake(self.view.frame.size.width / 2.0, self.view.frame.size.height / 2.0)]; //开始显示Loading动画 [indicator startAnimating]; [self.view addSubview:indicator]; [indicator release]; } //开始显示Loading动画 [indicator startAnimating];
// 停止动画
UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[self.view viewWithTag:103];
//停止显示Loading动画
[indicator stopAnimating];