Progress View

Currently, the progress bar view has 5 different types, which are spiner, circle, arc rotation, bar and stripBar, As shown below:

xib-based

  • Drag 5 NSView controls into the view interface, change their custom class name to the component class, and connect these progress views outlet.
  • Add 2 NSButton controls to view interface, these buttons action will be startAction: and stopAction:, respectively. In HDProgressViewVC.swift, add implementation for these action method.

The reference code is implemented as follows:

import Cocoa
class HDProgressViewVC: NSViewController {
    
    @IBOutlet  var spinerProgress: HDSpinerProgress!
    @IBOutlet  var circleProgress: HDCircleProgres!
    @IBOutlet  var arcProgress:    HDArcRotationProgress!
    @IBOutlet  var barProgress:    HDBarProgress!
    @IBOutlet  var stripProgress:  HDStripBarProgress!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
    }
    
    @IBAction func startAction(_ sender: AnyObject) {
        spinerProgress.startAnimation(self)
        arcProgress.startAnimation(self)
        barProgress.startAnimation(self)
        stripProgress.startAnimation(self)
    }
    
    @IBAction func stopAction(_ sender: AnyObject) {
        spinerProgress.stopAnimation(self)
        arcProgress.stopAnimation(self)
        barProgress.stopAnimation(self)
        stripProgress.stopAnimation(self)
    }
}

code-based

class ViewController: NSViewController {
    lazy var stripProgress: HDStripBarProgress = {
        let progress = HDStripBarProgress(frame: NSRect(x: 100, y: 100, width: 120, height: 18))
        return progress
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addSubview(stripProgress)
        self.view.addSubview(startButton)
        self.view.addSubview(stopButton)
    }
    
    
    lazy var startButton: NSButton = {
        let btn = NSButton(frame: NSRect(x: 100, y: 140, width: 120, height: 28))
        btn.setButtonType(.momentaryPushIn)
        btn.bezelStyle = .regularSquare
        btn.isBordered = true
        btn.title = "Start Progress"
        btn.target = self
        btn.action = #selector(self.startProgressAction(_:))
        return btn
    }()
    
    lazy var stopButton: NSButton = {
        let btn = NSButton(frame: NSRect(x: 220, y: 140, width: 120, height: 28))
        btn.setButtonType(.momentaryPushIn)
        btn.bezelStyle = .regularSquare
        btn.isBordered = true
        btn.title = "Stop Progress"
        btn.target = self
        btn.action = #selector(self.stopProgressAction(_:))
        return btn
    }()
    
    
    
    @IBAction func startProgressAction(_ sender: Any) {
        stripProgress.startAnimation(self)
    }
    
    
    
    @IBAction func stopProgressAction(_ sender: Any) {
        stripProgress.stopAnimation(self)
        
    }
    
}