您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 使用技巧 >> iOS 技巧大全

iOS 圓形進度條與計時功能

編輯:iOS 技巧大全

圓形進度條常用於倒數、載入或安全驗證等情境。可透過 UIBezierPath 繪製圓弧,再搭配 NSTimer 更新進度。

繪製圓弧

UIBezierPath *path = [UIBezierPath bezierPath];
[path addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
path.lineWidth = lineWidth;
[[UIColor redColor] set];
[path stroke];

若希望從 12 點方向開始,可將起始角度設為 -0.5π;結束角度則依剩餘時間比例計算。

計時更新

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];

若需要顯示秒數,可將剩餘時間向上取整,避免畫面數字與進度不一致。

UIPickerView 循環

系統 pickerView 沒有內建循環,但可建立大量重複資料,並將初始位置設在中段,讓使用者短時間內不易捲到頭。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved