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(label)
|
||||||
addSubview(toggleView)
|
addSubview(toggleView)
|
||||||
|
|
||||||
let heightEqual = heightAnchor.constraint(equalToConstant: toggleContainerSize.height)
|
label.widthLessThanEqualTo(labelMaxWidth)
|
||||||
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
|
|
||||||
|
|
||||||
// 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
|
||||||
|
|
||||||
labelConstraints = [
|
labelConstraints = [
|
||||||
heightEqual, heightGreater,
|
height(constant: toggleContainerSize.height, priority: .defaultLow),
|
||||||
|
heightGreaterThanEqualTo(constant: toggleContainerSize.height, priority: .defaultHigh),
|
||||||
label.topAnchor.constraint(equalTo: topAnchor),
|
label.topAnchor.constraint(equalTo: topAnchor),
|
||||||
label.bottomAnchor.constraint(equalTo: bottomAnchor),
|
label.bottomAnchor.constraint(equalTo: bottomAnchor),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -117,18 +117,22 @@ open class ToggleView: Control, Changeable {
|
|||||||
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
|
|
||||||
addSubview(toggleView)
|
addSubview(toggleView)
|
||||||
toggleView.addSubview(knobView)
|
toggleView.addSubview(knobView)
|
||||||
|
|
||||||
toggleView.pinToSuperView()
|
toggleView.pinToSuperView()
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
toggleView.widthAnchor.constraint(equalToConstant: toggleSize.width),
|
toggleView
|
||||||
toggleView.heightAnchor.constraint(equalToConstant: toggleSize.height),
|
.width(toggleSize.width)
|
||||||
knobView.heightAnchor.constraint(equalToConstant: knobSize.height),
|
.height(toggleSize.height)
|
||||||
knobView.widthAnchor.constraint(equalToConstant: knobSize.width),
|
|
||||||
knobView.centerYAnchor.constraint(equalTo: toggleView.centerYAnchor),
|
knobView
|
||||||
knobView.topAnchor.constraint(greaterThanOrEqualTo: toggleView.topAnchor)
|
.pinTopGreaterThanOrEqualTo()
|
||||||
])
|
.width(knobSize.width)
|
||||||
|
.height(knobSize.height)
|
||||||
|
|
||||||
|
knobView.centerYAnchor.constraint(equalTo: toggleView.centerYAnchor).activate()
|
||||||
|
|
||||||
// Set cornerRadius
|
// Set cornerRadius
|
||||||
knobView.layer.cornerRadius = knobSize.height / 2.0
|
knobView.layer.cornerRadius = knobSize.height / 2.0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user