I have a view controller where a UISwitch is used to enable resp. disable a UISlider:
class ViewController: UIViewController {
...
@IBOutlet weak var slider: UISlider!
@IBAction func doToggle(_ sender: UISwitch) {
slider.isEnabled = sender.isOn
}
...
}
When doToggle is executed and slider.isEnabled is set to false the slider cannot be moved anymore which is expected behavior. Unexpectedly though, any blue color left to the knob remains unchanged and the slider looks as if it were still enabled.
I can only force the color change by adding an explicit call to setNeedsLayout().
@IBAction func doToggle(_ sender: UISwitch) {
slider.isEnabled = sender.isOn
slider.setNeedsLayout()
}
I am now wondering whether this a bug. Note that enabling / disabling a UIButton immediately also gives visual feedback that the button is enabled resp. disabled and there is no need to call setNeedsLayout().
Any insights are highly appreciated.