首页 > 代码库 > Loading效果 UIActivityIndicatorView

Loading效果 UIActivityIndicatorView

//初始化:
UIActivityIndicatorView* indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

//设置显示样式,见UIActivityIndicatorViewStyle的定义
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

//设置显示位置
[indicator setCenter:CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2)];

//设置背景色
indicator.backgroundColor = UIColor.gray.

//设置背景透明
indicator.alpha = 0.5;

//设置背景为圆角矩形
indicator.layer.cornerRadius = 6;
indicator.layer.masksToBuounds = YES;

//将初始化好的indicator add到view中
[view addSubView:indicator];

//开始显示Loading动画
[indicator startAnimating];

//停止显示Loading动画
[indicator stopAnimating];