1.新建一個(gè)類MyActivityIndicatorView,繼承于UIActivityIndicatorView,添加初始化方法
先定義宏(模擬器為iPhone6)
#define kWidth 375
#define KHeight 667
#define MYCOLOR [UIColor blackColor]
- (id)initWithFrame:(CGRect)frame
{
? ? self = [super initWithFrame:frame];
? ? if (self) {
? ? ? ? // 菊花背景的大小
? ? ? ? self.frame = CGRectMake(kWidth/2-50, KHeight/2-50, 100, 100);
? ? ? ? // 菊花的背景色
? ? ? ? self.backgroundColor = MYCOLOR;
? ? ? ? self.layer.cornerRadius = 10;
? ? ? ? // 菊花的顏色和格式(白色、白色大、灰色)
? ? ? ? self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
? ? ? ? // 在菊花下面添加文字
? ? ? ? UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 60, 80, 40)];
? ? ? ? label.text = @"loading...";
? ? ? ? label.font = [UIFont systemFontOfSize:14];
? ? ? ? label.textAlignment = NSTextAlignmentCenter;
? ? ? ? label.textColor = [UIColor whiteColor];
? ? ? ? [self addSubview:label];
? ? }
? ? return? self;
}
2.在加載網(wǎng)絡(luò)之前調(diào)用該方法
// 自帶菊花方法
? ? self.myActivityIndicatorView = [[MyActivityIndicatorView alloc]init];
? ? [self.view addSubview:_myActivityIndicatorView];
? ? // 動(dòng)畫開始
? ? [_myActivityIndicatorView startAnimating];
3.網(wǎng)絡(luò)請(qǐng)求完成,數(shù)據(jù)加載后調(diào)用取消動(dòng)畫方法
// 動(dòng)畫結(jié)束
? ? [_myActivityIndicatorView stopAnimating];