mvm_core_ui/MVMCoreUI/Molecules/ProgressBar.swift
2019-05-16 15:39:29 -04:00

56 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 {
get {
return 10
}
set {
heightAnchor.constraint(equalToConstant: CGFloat(newValue)).isActive = true
switch isRounded {
case true:
progressViewStyle = .bar
default:
layer.cornerRadius = CGFloat((newValue ?? Float(0.0))/2)
clipsToBounds = true
}
}
}
open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
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)
}
}
if let barStyleUnwrapped = json?["barStyle"] as? Bool {
isRounded = barStyleUnwrapped
}
}
}