82 lines
2.3 KiB
Swift
82 lines
2.3 KiB
Swift
//
|
|
// ProgressBar.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Panth Patel on 5/3/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@objcMembers open class ProgressBar: UIProgressView, MVMCoreUIMoleculeViewProtocol, MVMCoreViewProtocol {
|
|
var isRounded = false
|
|
var thickness: CGFloat = 8.0 {
|
|
willSet(newValue) {
|
|
heightAnchor.constraint(equalToConstant: newValue).isActive = true
|
|
if isRounded {
|
|
layer.cornerRadius = newValue/2.0
|
|
} else {
|
|
progressViewStyle = .bar
|
|
}
|
|
}
|
|
}
|
|
|
|
public override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
setupView()
|
|
}
|
|
|
|
public required init?(coder aDecoder: NSCoder) {
|
|
super.init(coder: aDecoder)
|
|
setupView()
|
|
}
|
|
|
|
init() {
|
|
super.init(frame: .zero)
|
|
setupView()
|
|
}
|
|
|
|
// MARK: - MVMCoreViewProtocol
|
|
public func setupView() {
|
|
clipsToBounds = true
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
reset()
|
|
}
|
|
|
|
public func updateView(_ size: CGFloat) {
|
|
}
|
|
|
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
|
public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
|
if let isRounded = json?.optionalBoolForKey("roundedRect") {
|
|
self.isRounded = isRounded
|
|
}
|
|
if let thickness = json?.optionalCGFloatForKey("thickness") {
|
|
self.thickness = thickness
|
|
}
|
|
if let percentage = json?["percent"] as? Float {
|
|
progress = percentage/100.0
|
|
}
|
|
if let progressColor = json?.optionalStringForKey("progressColor") {
|
|
progressTintColor = UIColor.mfGet(forHex: progressColor)
|
|
}
|
|
if let backgroundColor = json?.optionalStringForKey("backgroundColor") {
|
|
trackTintColor = UIColor.mfGet(forHex: backgroundColor)
|
|
}
|
|
}
|
|
|
|
public func reset() {
|
|
isRounded = false
|
|
thickness = 8
|
|
progress = 0
|
|
progressTintColor = UIColor.mfCerulean()
|
|
trackTintColor = UIColor.mfSilver()
|
|
}
|
|
|
|
public static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
|
return 8
|
|
}
|
|
}
|
|
|
|
|