@interface ViewController ()
//活动指示器
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView;
@end
/**
UIActivityIndicatorView Demo
*/
- (void) activityIndicatorDome{
//类型三种Lager White、White、Gray
self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
//set location
CGRect frame = self.activityIndicatorView.frame;
frame.origin = CGPointMake(140, 100);
self.activityIndicatorView.frame = frame;
//Animating 当运行时控件处于活动状态
//Hides When Stopped 控件处于非活动状态时隐藏
self.activityIndicatorView.hidesWhenStopped = false;
//add
[self.view addSubview:self.activityIndicatorView];
//定义一个控制按钮
UIButton *buttonUpload = [[UIButton alloc] initWithFrame:CGRectMake(130, 140, 120, 45)];
buttonUpload.backgroundColor = [UIColor grayColor];
buttonUpload.layer.cornerRadius = 10;
[buttonUpload setTitle:@"Upload" forState:UIControlStateNormal];
[buttonUpload addTarget:self action:@selector(startToMove:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttonUpload];
}
- (void)startToMove:(id)sender{
NSLog(@"%s", __func__);
if ([self.activityIndicatorView isAnimating]) {
[self.activityIndicatorView stopAnimating];
}else{
[self.activityIndicatorView startAnimating];
}
}