'How to change UIButton state programmatically in Swift

I develop app for drawing on screen. I have toolpanel with bunch of buttons. Some of them have to become disabled or pressed depending on current user action. How can I change UIControlState of buttons programmatically considering that "state" property is readonly? If it's impossible, what is alternative for this purpose?



Solution 1:[1]

Use the correct property to change the state. For example

button.isSelected = true

or

button.isHighlighted = true

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Retterdesdialogs