- A dynamically flowing progress bar.
- 一個動態流動的進度條.
dependencies: [
.package(url: "https://github.com/William-Weng/WWProgressView.git", .upToNextMajor(from: "1.1.0"))
]
函式 |
功能 |
settings(delegate:fps:radius:startAngle:angleSpeed:count:) |
基本參數設定 |
running() |
開始更新 |
stop() |
停止更新 |
函式 |
功能 |
percentage(_:) |
取得目前進度 (0% ~ 100%) |
import UIKit
import WWProgressView
final class ViewController: UIViewController {
@IBOutlet weak var myProgressView: WWProgressView!
private var percentage: Double = 0
private var timer: Timer? = Timer()
override func viewDidLoad() {
super.viewDidLoad()
initSetting()
}
@IBAction func running(_ sender: UIButton) { runningAction() }
@objc func timerAction(timer: Timer) { timerAction() }
}
extension ViewController: WWProgressViewDelegate {
func percentage(_ progressView: WWProgressView) -> Double {
return percentage
}
}
private extension ViewController {
func initSetting() {
myProgressView.settings(delegate: self, fps: 60, radius: 5, startAngle: 0, angleSpeed: 3, count: 5)
}
func runningAction() {
percentage = 60
myProgressView.running()
timer?.invalidate()
timer = nil
timer = Timer()
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(Self.timerAction(timer:)), userInfo: nil, repeats: true)
}
func timerAction() {
if (percentage > 100.0) {
timer?.invalidate()
timer = nil
myProgressView.stop()
return
}
percentage += 0.5
}
}