refactored toggle
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
17705efcb8
commit
50e8ea468a
@ -147,21 +147,14 @@ open class Toggle: Control, Changeable {
|
||||
addSubview(label)
|
||||
addSubview(toggleView)
|
||||
|
||||
let heightEqual = heightAnchor.constraint(equalToConstant: toggleContainerSize.height)
|
||||
heightEqual.priority = .defaultLow
|
||||
|
||||
let heightGreater = heightAnchor.constraint(greaterThanOrEqualToConstant: toggleContainerSize.height)
|
||||
heightGreater.priority = .defaultHigh
|
||||
|
||||
let labelWidth = label.widthAnchor.constraint(lessThanOrEqualToConstant: labelMaxWidth)
|
||||
labelWidth.priority = .required
|
||||
labelWidth.isActive = true
|
||||
label.widthLessThanEqualTo(labelMaxWidth)
|
||||
|
||||
// Set up initial constraints for label and switch
|
||||
toggleView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
||||
|
||||
labelConstraints = [
|
||||
heightEqual, heightGreater,
|
||||
height(constant: toggleContainerSize.height, priority: .defaultLow),
|
||||
heightGreaterThanEqualTo(constant: toggleContainerSize.height, priority: .defaultHigh),
|
||||
label.topAnchor.constraint(equalTo: topAnchor),
|
||||
label.bottomAnchor.constraint(equalTo: bottomAnchor),
|
||||
]
|
||||
|
||||
@ -117,18 +117,22 @@ open class ToggleView: Control, Changeable {
|
||||
|
||||
isAccessibilityElement = true
|
||||
accessibilityTraits = .button
|
||||
|
||||
|
||||
addSubview(toggleView)
|
||||
toggleView.addSubview(knobView)
|
||||
|
||||
toggleView.pinToSuperView()
|
||||
NSLayoutConstraint.activate([
|
||||
toggleView.widthAnchor.constraint(equalToConstant: toggleSize.width),
|
||||
toggleView.heightAnchor.constraint(equalToConstant: toggleSize.height),
|
||||
knobView.heightAnchor.constraint(equalToConstant: knobSize.height),
|
||||
knobView.widthAnchor.constraint(equalToConstant: knobSize.width),
|
||||
knobView.centerYAnchor.constraint(equalTo: toggleView.centerYAnchor),
|
||||
knobView.topAnchor.constraint(greaterThanOrEqualTo: toggleView.topAnchor)
|
||||
])
|
||||
|
||||
toggleView
|
||||
.width(toggleSize.width)
|
||||
.height(toggleSize.height)
|
||||
|
||||
knobView
|
||||
.pinTopGreaterThanOrEqualTo()
|
||||
.width(knobSize.width)
|
||||
.height(knobSize.height)
|
||||
|
||||
knobView.centerYAnchor.constraint(equalTo: toggleView.centerYAnchor).activate()
|
||||
|
||||
// Set cornerRadius
|
||||
knobView.layer.cornerRadius = knobSize.height / 2.0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user