UI第九节——UIProgressView
- (void)viewDidLoad {
[super viewDidLoad];
// 实例化 UIProgressView,高度是固定的
UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(40, 100, 295, 30)];
#if 1
// 主题颜色
progressView.progressTintColor = [UIColor redColor];
progressView.trackTintColor = [UIColor greenColor];
#endif
#if 0 // 这个有BUG,不显示
// 图片
progressView.progressImage = [UIImage imageNamed:@"slider_track_min"];
progressView.trackImage = [UIImage imageNamed:@"slider_track_max"];
#endif
// 把progressView加到self.view上
[self.view addSubview:progressView];
// 启动一个定时器
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerRunning:) userInfo:@{@"progressView": progressView} repeats:YES];
}
// 定时会调用一次这个函数
- (void)timerRunning:(NSTimer *)timer
{
UIProgressView *progressView = [timer.userInfo objectForKey:@"progressView"];
// 设置进度
progressView.progress += 0.1;
NSLog(@"%f", progressView.progress);
// 当进度条完全走完的时候,让定时器停掉
if (progressView.progress >= 1.0) {
// 销毁定时器
[timer invalidate];
}
}