ios进度条ProgressView

ios进度条ProgressView_第1张图片
图片.png
@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");
    }
}

你可能感兴趣的:(ios进度条ProgressView)