mvm_core_ui/MVMCoreUI/Molecules/ProgressBarView.swift
2019-06-04 11:52:56 -04:00

100 lines
5.9 KiB
Swift

//
// ProgressBarView.swift
// MVMCoreUI
//
// Created by Panth Patel on 5/3/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import UIKit
@objcMembers public class ProgressBarView: ViewConstrainingView {
var progress = ProgressBar()
var topleftlabel = Label()
var toprightlabel = Label()
var bottomleftlabel = Label()
var bottomrightlabel = Label()
open override func needsToBeConstrained() -> Bool {
return true
}
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
progress.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
let topleftlabeljson = json?.optionalDictionaryForKey("label")
let toprightlabeljson = json?.optionalDictionaryForKey("toprightlabel")
let bottomleftlabeljson = json?.optionalDictionaryForKey("bottomleftlabel")
let bottomrightlabeljson = json?.optionalDictionaryForKey("bottomrightlabel")
topleftlabel.setWithJSON(topleftlabeljson, delegateObject: delegateObject, additionalData: additionalData)
toprightlabel.setWithJSON(toprightlabeljson, delegateObject: delegateObject, additionalData: additionalData)
bottomleftlabel.setWithJSON(bottomleftlabeljson, delegateObject: delegateObject, additionalData: additionalData)
bottomrightlabel.setWithJSON(bottomrightlabeljson, delegateObject: delegateObject, additionalData: additionalData)
}
override open func setupView() {
super.setupView()
addSubview(topleftlabel)
addSubview(toprightlabel)
addSubview(bottomleftlabel)
addSubview(bottomrightlabel)
addSubview(progress)
progress.translatesAutoresizingMaskIntoConstraints = false
topleftlabel.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
topleftlabel.topAnchor.constraint(equalTo: self.topAnchor).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)
NSLayoutConstraint(item: toprightlabel, attribute: .leading, relatedBy: .equal, toItem: topleftlabel, attribute: .trailing, multiplier: 1.0, constant: PaddingTwo).isActive = true
toprightlabel.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
toprightlabel.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
toprightlabel.textAlignment = .right
toprightlabel.setContentHuggingPriority(UILayoutPriority(802), for: .horizontal)
toprightlabel.setContentHuggingPriority(UILayoutPriority(802), for: .vertical)
var topconstraint = progress.topAnchor.constraint(equalTo: topleftlabel.bottomAnchor, constant: PaddingTwo)
topconstraint.priority = UILayoutPriority(249)
topconstraint.isActive = true
progress.topAnchor.constraint(greaterThanOrEqualTo: topleftlabel.bottomAnchor, constant: PaddingTwo).isActive = true
topconstraint = progress.topAnchor.constraint(equalTo: toprightlabel.bottomAnchor, constant: PaddingTwo)
topconstraint.priority = UILayoutPriority(249)
topconstraint.isActive = true
progress.topAnchor.constraint(greaterThanOrEqualTo: toprightlabel.bottomAnchor, constant: PaddingTwo).isActive = true
progress.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
progress.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
bottomleftlabel.topAnchor.constraint(equalTo: progress.bottomAnchor, constant: PaddingTwo).isActive = true
bottomleftlabel.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
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(802), for: .horizontal)
bottomrightlabel.setContentHuggingPriority(UILayoutPriority(802), for: .vertical)
var bottomconstraint = bottomAnchor.constraint(equalTo: bottomleftlabel.bottomAnchor, constant: PaddingTwo)
bottomconstraint.priority = UILayoutPriority(249)
bottomconstraint.isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: bottomleftlabel.bottomAnchor, constant: PaddingTwo).isActive = true
bottomconstraint = bottomAnchor.constraint(equalTo: bottomrightlabel.bottomAnchor, constant: PaddingTwo)
bottomconstraint.priority = UILayoutPriority(249)
bottomconstraint.isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: bottomrightlabel.bottomAnchor, constant: PaddingTwo).isActive = true
}
}