ios进度条ProgressView

图片.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");
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容