From 5043964c290074d31cc47c9043a8e36510358e3e Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 3 Oct 2019 16:43:58 -0400 Subject: [PATCH] revised alignment for case when no label. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 5 ++- .../Atoms/Views/CheckboxWithLabelView.swift | 35 ++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 77a1f342..bf8407be 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -335,7 +335,10 @@ import MVMCore } open func reset() { - setupView() + + backgroundColor = nil + shapeLayer = nil + isSelected = false } open func setAsMolecule() { diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index e9aa0d0e..55339e61 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -53,7 +53,7 @@ addSubview(checkbox) addSubview(label) - label.setContentCompressionResistancePriority(.required, for: .vertical) + label.text = "" let dimension = sizeObject?.getValueBasedOnApplicationWidth() ?? Checkbox.defaultHeightWidth checkboxWidthConstraint = checkbox.heightAnchor.constraint(equalToConstant: dimension) @@ -64,13 +64,17 @@ checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true let generalTop = checkbox.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor) - generalTop.priority = UILayoutPriority(rawValue: 750) + generalTop.priority = UILayoutPriority(800) generalTop.isActive = true let generalBottom = checkbox.bottomAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.bottomAnchor) - generalBottom.priority = UILayoutPriority(rawValue: 750) + generalBottom.priority = UILayoutPriority(800) generalBottom.isActive = true + let checboxBottom = checkbox.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor) + checboxBottom.priority = UILayoutPriority(249) + checboxBottom.isActive = true + // Allows various positions of checkbox. checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor) checkboxTopConstraint = checkbox.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor) @@ -79,9 +83,17 @@ label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true layoutMarginsGuide.trailingAnchor.constraint(equalTo: label.trailingAnchor).isActive = true label.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: PaddingTwo).isActive = true - layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true - alignSubviews(by: .center) + let bottomLabelConstraint = layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor) + bottomLabelConstraint.priority = UILayoutPriority(500) + bottomLabelConstraint.isActive = true + + // layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true + // let labelBottom = label.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor) + // labelBottom.priority = UILayoutPriority(249) + // labelBottom.isActive = true + + alignCheckbox(.center) } //-------------------------------------------------- @@ -105,7 +117,7 @@ public convenience init(position: CheckboxPosition) { self.init(frame: .zero) - alignSubviews(by: position) + alignCheckbox(position) } //-------------------------------------------------- @@ -113,7 +125,7 @@ //-------------------------------------------------- /// Aligns Checkbox and Label relative to the desired position of the Checkbox. - private func alignSubviews(by position: CheckboxPosition) { + private func alignCheckbox(_ position: CheckboxPosition) { checkboxPosition = position switch position { @@ -166,13 +178,20 @@ extension CheckboxWithLabelView { super.resetConstraints() } + open override func reset() { + super.reset() + + label.text = "" + checkbox.reset() + } + override open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) guard let dictionary = json else { return } if let checkboxAlignment = dictionary["checkboxAlignment"] as? String, let position = CheckboxPosition(rawValue: checkboxAlignment) { - alignSubviews(by: position) + alignCheckbox(position) } checkbox.setWithJSON(dictionary.dictionaryForKey("checkbox"), delegateObject: delegateObject, additionalData: additionalData)