UIActivityIndicatorView* Activity = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 20, 100, 100)];
//设置活动指示器的风格类型
Activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
//开启活动指示器的活动状态
//[Activity startAnimating];
//结束活动指示器的活动状态
//[Activity stopAnimating];
//设置活动指示器停止时是否隐藏,YES隐藏,NO不隐藏
//Activity.hidesWhenStopped = NO;
Activity.tag = 1;
[self.view addSubview:Activity];
UISwitch* swit = [[UISwitch alloc]initWithFrame:CGRectMake(30, 130, 100, 100)];
[swit addTarget:self action:@selector(switAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:swit];
调用的方法:
-(void)switAction:(UISwitch*)sender
{
UIActivityIndicatorView* Activity = [self.view viewWithTag:1];
if (sender.on == YES) {
[Activity startAnimating];
}else{
[Activity stopAnimating];
}
}