@interface ViewController ()
//进度条
@property (nonatomic, strong) UIProgressView *progressView;
@property (nonatomic, strong) NSTimer *timer;
@end
/**
UIProgressView Demo
*/
- (void)progressDemo{
//添加一个控制按钮
UIButton *buttonDownload = [[UIButton alloc] initWithFrame:CGRectMake(130, 140, 120, 45)];
buttonDownload.backgroundColor = [UIColor grayColor];
buttonDownload.layer.cornerRadius = 10;
[buttonDownload setTitle:@"Download" forState:UIControlStateNormal];
[buttonDownload addTarget:self action:@selector(downloadProgress:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttonDownload];
//进度条
self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(90, 260, 200, 2)];
[self.view addSubview:self.progressView];
}
- (void)downloadProgress:(id)sender{
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(download) userInfo:nil repeats:true];
}
- (void)download{
self.progressView.progress += 0.01;
if (self.progressView.progress == 1) {
[self.timer invalidate];
NSLog(@"accomplish");
}
}