#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UIActivityIndicatorView *activityIndicatorView;
@property (nonatomic,assign) BOOL isOn;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.activityIndicatorView];
}
- (UIActivityIndicatorView *)activityIndicatorView {
if (!_activityIndicatorView) {
_activityIndicatorView = [[UIActivityIndicatorView alloc] init];
_activityIndicatorView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2);
_activityIndicatorView.color = [UIColor redColor];
_activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleLarge;
[_activityIndicatorView startAnimating];
[_activityIndicatorView setHidesWhenStopped:YES];
}
return _activityIndicatorView;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
_isOn = !_isOn;
if (_isOn) {
[self.activityIndicatorView stopAnimating];
} else {
[self.activityIndicatorView startAnimating];
}
}
@end
