diff --git a/MVMCoreUI/Molecules/ProgressBar.swift b/MVMCoreUI/Molecules/ProgressBar.swift index 301c645a..1ae7336a 100644 --- a/MVMCoreUI/Molecules/ProgressBar.swift +++ b/MVMCoreUI/Molecules/ProgressBar.swift @@ -10,7 +10,7 @@ import Foundation public class ProgressBar: UIProgressView { - public func styleprogessbar(json: Dictionary) -> UIProgressView { + public func styleprogessbar(json: Dictionary) { let percentage = Float(json["percent"] as! String) let barstyle = json["barStyle"] as! Bool let progresscolor = json["progressColor"] as! String @@ -29,7 +29,6 @@ public class ProgressBar: UIProgressView { self.clipsToBounds = true } - return self } } diff --git a/MVMCoreUI/Molecules/ProgressBarView.swift b/MVMCoreUI/Molecules/ProgressBarView.swift index a7350837..61cdde7b 100644 --- a/MVMCoreUI/Molecules/ProgressBarView.swift +++ b/MVMCoreUI/Molecules/ProgressBarView.swift @@ -12,6 +12,7 @@ import UIKit var progress = ProgressBar() var descriptionLabel = Label() + var thickness: Float? public init() { super.init(frame: .zero) @@ -29,12 +30,6 @@ import UIKit super.updateView(size) } -// public init(withJSON json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { -// super.init(frame: CGRect(x:0, y:0, width:400, height:80)) -// setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) -// } -// - open override func needsToBeConstrained() -> Bool { return true } @@ -43,135 +38,40 @@ import UIKit super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - progress.styleprogessbar(json: json as! Dictionary) + if let jsonUnwrapped = json as? Dictionary { + progress.styleprogessbar(json: jsonUnwrapped) + } + let textlabeljson = json!["label"] as! Dictionary //UILabel.init(frame: CGRect(x:0, y:0, width: 300, height: 300)) self.descriptionLabel.setWithJSON(textlabeljson, delegateObject: delegateObject, additionalData: additionalData) - let thickness = Float(json!["thickness"] as! String) - - - - - -// let leadingconstraint = NSLayoutConstraint(item: progressUI, -// attribute: .leading, -// relatedBy: .equal, -// toItem: self, -// attribute: .leading, -// multiplier: 1, -// constant: 20) -// -// -// -// let topconstraint = NSLayoutConstraint(item: progressUI, -// attribute: .top, -// relatedBy: .equal, -// toItem: self, -// attribute: .top, -// multiplier: 1, -// constant: 0) -// let widthconstraint = NSLayoutConstraint(item: progressUI, -// attribute: .width, -// relatedBy: .equal, -// toItem: nil, -// attribute: .notAnAttribute, -// multiplier: 1, -// constant: 350) - NSLayoutConstraint(item: progress, - attribute: .height, - relatedBy: .equal, - toItem: nil, - attribute: .notAnAttribute, - multiplier: 1, - constant: (CGFloat(thickness!))) - - // progressUI.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true - -// self.addConstraints([leadingconstraint, topconstraint, widthconstraint, heightconstraint]) - // self.backgroundColor = .blue - + thickness = Float(json!["thickness"] as! String) + // thickness = 20.0 } override open func setupView() { super.setupView() translatesAutoresizingMaskIntoConstraints = false - self.addSubview(descriptionLabel) + addSubview(descriptionLabel) addSubview(progress) progress.translatesAutoresizingMaskIntoConstraints = false descriptionLabel.translatesAutoresizingMaskIntoConstraints = false - // descriptionLabel.topAnchor.constraint(equalTo: self.topAnchor, constant: 25).isActive = true -// descriptionLabel.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true -// descriptionLabel.heightAnchor.constraint(equalTo: self.heightAnchor).isActive = true - let vericalSpacing = MFStyler.defaultVerticalPaddingForApplicationWidth() - let horizontalSpacing = MFStyler.defaultHorizontalPaddingForApplicationWidth() -// let leadingconstraint = NSLayoutConstraint(item: descriptionLabel, -// attribute: .leading, -// relatedBy: .equal, -// toItem: self, -// attribute: .leading, -// multiplier: 1, -// constant: 20) -// -// let trailingconstraint = NSLayoutConstraint(item: descriptionLabel, -// attribute: .trailing, -// relatedBy: .equal, -// toItem: self, -// attribute: .trailing, -// multiplier: 1, -// constant: 20) descriptionLabel.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true descriptionLabel.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true - - descriptionLabel.topAnchor.constraint(equalTo: self.topAnchor, constant: vericalSpacing).isActive = true - descriptionLabel.bottomAnchor.constraint(equalTo: progress.topAnchor, constant: vericalSpacing).isActive = true - + descriptionLabel.topAnchor.constraint(equalTo: self.topAnchor).isActive = true + descriptionLabel.numberOfLines = 0 + descriptionLabel.sizeToFit() progress.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true progress.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true - progress.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: vericalSpacing).isActive = true -// progress.topAnchor.constraint(equalTo: descriptionLabel.bottomAnchor, constant: vericalSpacing).isActive = true + progress.heightAnchor.constraint(equalToConstant: 20).isActive = true + progress.topAnchor.constraint(equalTo: descriptionLabel.bottomAnchor, constant: vericalSpacing).isActive = true + progress.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true - - /* let topconstraint = NSLayoutConstraint(item: descriptionLabel, - attribute: .top, - relatedBy: .equal, - toItem: self, - attribute: .top, - multiplier: 1, - constant: 0) */ - -// let bottomconstraint = NSLayoutConstraint(item: descriptionLabel, -// attribute: .bottom, -// relatedBy: .equal, -// toItem: self, -// attribute: .bottom, -// multiplier: 1, -// constant: 1) - -// NSLayoutConstraint.constraintPinSubview(descriptionLabel, pinCenterX: true, pinCenterY: false) -// NSLayoutConstraint.constraintPinSubview(descriptionLabel, pinTop: true, pinBottom: true, pinLeft: true, pinRight: true) -// let widthconstraint = NSLayoutConstraint(item: descriptionLabel, -// attribute: .width, -// relatedBy: .equal, -// toItem: nil, -// attribute: .width, -// multiplier: 1, -// constant: 350) -// -// let heightconstraint = NSLayoutConstraint(item: descriptionLabel, -// attribute: .height, -// relatedBy: .equal, -// toItem: nil, -// attribute: .height, -// multiplier: 1, -// constant: 30) - -// self.addConstraints([leadingconstraint,trailingconstraint]) - }