Skip to content

William-Weng/WWProgressView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WWProgressView

Swift-5.7 iOS-16.0 TAG Swift Package Manager-SUCCESS LICENSE

  • A dynamically flowing progress bar.
  • 一個動態流動的進度條.
Example.mp4
dependencies: [
    .package(url: "https://github.com/William-Weng/WWProgressView.git", .upToNextMajor(from: "1.2.0"))
]

Function - 可用函式

函式 功能
settings(delegate:fullImage:progressImage:fps:radius:startAngle:angleSpeed:count:) 基本參數設定
running() 開始更新
stop() 停止更新

WWProgressView.Delegate

函式 功能
percentage(_:) 取得目前進度 (0% ~ 100%)

Example

import UIKit
import WWProgressView

final class ViewController: UIViewController {

    @IBOutlet weak var myProgressView: WWProgressView!
    @IBOutlet weak var myButton: UIButton!
    
    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() }
}

// MARK: - WWProgressView.Delegate
extension ViewController: WWProgressView.Delegate {
    
    func percentage(_ progressView: WWProgressView) -> Double {
        return percentage
    }
}

// MARK: - 小工具
private extension ViewController {
    
    /// 初始化設定
    func initSetting() {
        myProgressView.settings(delegate: self, fullImage: UIImage(named: "FullWater"), progressImage: UIImage(named: "EmptyWater"))
    }
    
    /// 開始更新
    func runningAction() {
        
        percentage = 0
        myProgressView.running()
        
        timer?.invalidate()
        timer = nil
        timer = Timer()
        timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(Self.timerAction(timer:)), userInfo: nil, repeats: true)
    }
    
    /// 更新進度值
    func timerAction() {
        
        if (percentage < 100.0) { percentage += 0.2; return }
        
        timer?.invalidate()
        timer = nil
        myProgressView.stop()
        myButton.setTitle("~裝滿了~", for: .normal)
        myButton.backgroundColor = .black
    }
}

About

A dynamically flowing progress bar.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages