added label width and update anchor on right
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
a93edcc5ea
commit
efc15eabdf
@ -153,6 +153,10 @@ open class Toggle: Control, Changeable {
|
|||||||
let heightGreater = heightAnchor.constraint(greaterThanOrEqualToConstant: toggleContainerSize.height)
|
let heightGreater = heightAnchor.constraint(greaterThanOrEqualToConstant: toggleContainerSize.height)
|
||||||
heightGreater.priority = .defaultHigh
|
heightGreater.priority = .defaultHigh
|
||||||
|
|
||||||
|
let labelWidth = label.widthAnchor.constraint(lessThanOrEqualToConstant: labelMaxWidth)
|
||||||
|
labelWidth.priority = .required
|
||||||
|
labelWidth.isActive = true
|
||||||
|
|
||||||
// Set up initial constraints for label and switch
|
// Set up initial constraints for label and switch
|
||||||
toggleView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
toggleView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
||||||
|
|
||||||
@ -171,7 +175,7 @@ open class Toggle: Control, Changeable {
|
|||||||
rightConstraints = [
|
rightConstraints = [
|
||||||
toggleView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
toggleView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||||
label.leadingAnchor.constraint(equalTo: toggleView.trailingAnchor, constant: spacingBetween),
|
label.leadingAnchor.constraint(equalTo: toggleView.trailingAnchor, constant: spacingBetween),
|
||||||
label.trailingAnchor.constraint(equalTo: trailingAnchor)
|
label.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor)
|
||||||
]
|
]
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -227,6 +231,7 @@ open class Toggle: Control, Changeable {
|
|||||||
private var showLabel: Bool {
|
private var showLabel: Bool {
|
||||||
showText && !statusText.isEmpty
|
showText && !statusText.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateLabel() {
|
private func updateLabel() {
|
||||||
label.isHidden = !showLabel
|
label.isHidden = !showLabel
|
||||||
|
|
||||||
@ -250,7 +255,6 @@ open class Toggle: Control, Changeable {
|
|||||||
NSLayoutConstraint.deactivate(rightConstraints)
|
NSLayoutConstraint.deactivate(rightConstraints)
|
||||||
NSLayoutConstraint.deactivate(labelConstraints)
|
NSLayoutConstraint.deactivate(labelConstraints)
|
||||||
}
|
}
|
||||||
invalidateIntrinsicContentSize()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user