-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathUIProgressView.swift
42 lines (35 loc) · 1.05 KB
/
UIProgressView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// UIProgressView.swift
// UIKit
//
// Created by Michael Knoch on 07.09.17.
// Copyright © 2017 flowkey. All rights reserved.
//
open class UIProgressView: UIView {
let progressLayer = CALayer()
open var progress: Float = 0 {
didSet { setNeedsLayout() }
}
public var progressTintColor: UIColor? {
didSet { progressLayer.backgroundColor = progressTintColor?.cgColor }
}
public var trackTintColor: UIColor? {
didSet { backgroundColor = trackTintColor }
}
public func setProgress(_ progress: Float, animated: Bool) {
CATransaction.begin()
CATransaction.setDisableActions(!animated)
self.progress = progress
CATransaction.commit()
}
public init() {
super.init(frame: .zero)
layer.addSublayer(progressLayer)
}
override open func layoutSubviews() {
super.layoutSubviews()
progressLayer.frame = bounds
progressLayer.cornerRadius = layer.cornerRadius
progressLayer.frame.width = bounds.width * CGFloat(progress)
}
}