mvm_core_ui/MVMCoreUI/Molecules/ProgressBar.swift
2019-05-20 17:14:21 -04:00

50 lines
1.6 KiB
Swift

//
// ProgressBar.swift
// MVMCoreUI
//
// Created by Panth Patel on 5/3/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import Foundation
public class ProgressBar: UIProgressView {
var isRounded = Bool()
var thickness : Float = 0.0 {
willSet(newValue) {
heightAnchor.constraint(equalToConstant: CGFloat(newValue)).isActive = true
switch isRounded {
case true:
layer.cornerRadius = CGFloat((newValue ?? Float(0.0))/2)
clipsToBounds = true
default:
progressViewStyle = .bar
}
}
}
open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
isRounded = json?.optionalBoolForKey("roundedRect") ?? false
thickness = json?.floatFromStringForKey("thickness") ?? Float(0.0)
let percentage = json?.floatFromStringForKey("percent")
progress = (percentage ?? Float(0.0))/100
progressTintColor = UIColor.mfBattleshipGrey()
trackTintColor = UIColor.mfLighterGray()
if let progresscolor = json?.optionalStringForKey("progressColor") {
if !progresscolor.isEmpty {
progressTintColor = UIColor.mfGet(forHex: progresscolor)
}
}
if let backgroundcolor = json?.optionalStringForKey("backgroundColor") {
if !backgroundcolor.isEmpty {
trackTintColor = UIColor.mfGet(forHex: backgroundcolor)
}
}
}
}