实现代码
self.activityIndicatorView=[[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
self.activityIndicatorView.center=self.view.center;
//设置样式
[self.activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
[self.activityIndicatorView setBackgroundColor:[UIColor lightGrayColor]];
[self.view addSubview:self.activityIndicatorView];
//开始动画
[self.activityIndicatorView startAnimating];
关于style的设置,有三种白色和灰色,这两种的尺寸都是20*20,白色大图是37*37:
typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) {
UIActivityIndicatorViewStyleWhiteLarge,
UIActivityIndicatorViewStyleWhite,
UIActivityIndicatorViewStyleGray,
};
关闭动画
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5* NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
[self.activityIndicatorView stopAnimating];
});