From 145cafbc3026336d7637c66f08e39677e6c8d537 Mon Sep 17 00:00:00 2001 From: Panth Patel Date: Mon, 20 May 2019 17:14:21 -0400 Subject: [PATCH] ProgreessBar Modifications --- MVMCoreUI/Atoms/Views/ProgressBar.json | 0 MVMCoreUI/Molecules/ProgressBar.swift | 16 +++++----------- MVMCoreUI/Molecules/ProgressBarView.swift | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 22 deletions(-) delete mode 100644 MVMCoreUI/Atoms/Views/ProgressBar.json diff --git a/MVMCoreUI/Atoms/Views/ProgressBar.json b/MVMCoreUI/Atoms/Views/ProgressBar.json deleted file mode 100644 index e69de29b..00000000 diff --git a/MVMCoreUI/Molecules/ProgressBar.swift b/MVMCoreUI/Molecules/ProgressBar.swift index f868bbf5..fb417931 100644 --- a/MVMCoreUI/Molecules/ProgressBar.swift +++ b/MVMCoreUI/Molecules/ProgressBar.swift @@ -11,23 +11,21 @@ import Foundation public class ProgressBar: UIProgressView { var isRounded = Bool() - var thickness : Float { - get { - return 10 - } - set { + var thickness : Float = 0.0 { + willSet(newValue) { heightAnchor.constraint(equalToConstant: CGFloat(newValue)).isActive = true switch isRounded { case true: - progressViewStyle = .bar - default: 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 @@ -45,10 +43,6 @@ public class ProgressBar: UIProgressView { trackTintColor = UIColor.mfGet(forHex: backgroundcolor) } } - - if let barStyleUnwrapped = json?["barStyle"] as? Bool { - isRounded = barStyleUnwrapped - } } } diff --git a/MVMCoreUI/Molecules/ProgressBarView.swift b/MVMCoreUI/Molecules/ProgressBarView.swift index 1778c555..04eb9046 100644 --- a/MVMCoreUI/Molecules/ProgressBarView.swift +++ b/MVMCoreUI/Molecules/ProgressBarView.swift @@ -47,9 +47,9 @@ import UIKit topleftlabel.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true topleftlabel.topAnchor.constraint(equalTo: self.topAnchor).isActive = true - let topleftconstraint = NSLayoutConstraint(item: topleftlabel, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 0.5, constant: 0.0) - topleftconstraint.priority = UILayoutPriority(rawValue: 100) - topleftconstraint.isActive = true + let topleftwidthconstraint = NSLayoutConstraint(item: topleftlabel, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 0.5, constant: 0.0) + topleftwidthconstraint.priority = UILayoutPriority(100) + topleftwidthconstraint.isActive = true topleftlabel.setContentHuggingPriority(UILayoutPriority(801), for: .horizontal) topleftlabel.setContentHuggingPriority(UILayoutPriority(801), for: .vertical) @@ -57,7 +57,7 @@ import UIKit toprightlabel.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true toprightlabel.topAnchor.constraint(equalTo: self.topAnchor).isActive = true toprightlabel.textAlignment = .right - toprightlabel.setContentHuggingPriority(UILayoutPriority(1000), for: .horizontal) + toprightlabel.setContentHuggingPriority(UILayoutPriority(802), for: .horizontal) toprightlabel.setContentHuggingPriority(UILayoutPriority(802), for: .vertical) var topconstraint = progress.topAnchor.constraint(equalTo: topleftlabel.bottomAnchor, constant: PaddingTwo) @@ -74,18 +74,18 @@ import UIKit bottomleftlabel.topAnchor.constraint(equalTo: progress.bottomAnchor, constant: PaddingTwo).isActive = true bottomleftlabel.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true - let bottomleftconstraint = NSLayoutConstraint(item: bottomleftlabel, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 0.5, constant: 0.0) - bottomleftconstraint.priority = UILayoutPriority(100) - bottomleftconstraint.isActive = true - bottomleftlabel.setContentHuggingPriority(UILayoutPriority(900), for: .horizontal) - bottomleftlabel.setContentHuggingPriority(UILayoutPriority(850), for: .vertical) + let bottomleftwidthconstraint = NSLayoutConstraint(item: bottomleftlabel, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 0.5, constant: 0.0) + bottomleftwidthconstraint.priority = UILayoutPriority(100) + bottomleftwidthconstraint.isActive = true + bottomleftlabel.setContentHuggingPriority(UILayoutPriority(801), for: .horizontal) + bottomleftlabel.setContentHuggingPriority(UILayoutPriority(801), for: .vertical) NSLayoutConstraint(item: bottomrightlabel, attribute: .leading, relatedBy: .equal, toItem: bottomleftlabel, attribute: .trailing, multiplier: 1.0, constant: PaddingTwo).isActive = true bottomrightlabel.topAnchor.constraint(equalTo: progress.bottomAnchor, constant: PaddingTwo).isActive = true bottomrightlabel.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true bottomrightlabel.textAlignment = .right - bottomrightlabel.setContentHuggingPriority(UILayoutPriority(1000), for: .horizontal) - bottomrightlabel.setContentHuggingPriority(UILayoutPriority(851), for: .vertical) + bottomrightlabel.setContentHuggingPriority(UILayoutPriority(802), for: .horizontal) + bottomrightlabel.setContentHuggingPriority(UILayoutPriority(802), for: .vertical) var bottomconstraint = bottomAnchor.constraint(equalTo: bottomleftlabel.bottomAnchor, constant: PaddingTwo) bottomconstraint.priority = UILayoutPriority(249)