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];
??? }
}
如果對你有幫助,請關注我哦!
轉載于:https://www.cnblogs.com/laolitou-ping/p/6244161.html
總結
以上是生活随笔為你收集整理的UI第九节——UIProgressView的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 反编译android的apk
- 下一篇: jee websocket搭建总结