圓形進度條常用於倒數、載入或安全驗證等情境。可透過 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];
若需要顯示秒數,可將剩餘時間向上取整,避免畫面數字與進度不一致。
系統 pickerView 沒有內建循環,但可建立大量重複資料,並將初始位置設在中段,讓使用者短時間內不易捲到頭。