revised alignment for case when no label.
This commit is contained in:
parent
44e420218d
commit
5043964c29
@ -335,7 +335,10 @@ import MVMCore
|
||||
}
|
||||
|
||||
open func reset() {
|
||||
setupView()
|
||||
|
||||
backgroundColor = nil
|
||||
shapeLayer = nil
|
||||
isSelected = false
|
||||
}
|
||||
|
||||
open func setAsMolecule() {
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user