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?
Asked
Active
Viewed 3.0k times
2 Answers
35
I think you're confused. UIControlState
is used to set up target/actions, or to change the appearance of the button for specific states (So, for example, you can specify the image that's used when it's selected, and a different image for when the button is not in the selected state.)
If you want to change the state to selected, you just set the selected property.
button.isSelected = true
Likewise for isEnabled:
button.isEnabled = false //disable the button

Duncan C
- 128,072
- 22
- 173
- 272
12
Use the correct property to change the state. For example
button.isSelected = true
or
button.isHighlighted = true

Retterdesdialogs
- 3,180
- 1
- 21
- 42
-
1This may be an old thread, but it looks like you beat me to the answer by a minute. I'm not sure why you didn't get the check or the votes, but I'm giving you my vote since you were first to answer correctly. – Duncan C May 10 '20 at 21:49
-
@DuncanC No problem for me. Im not searching for votes or checks, just want to help out people :) But thank you. – Retterdesdialogs Jun 03 '20 at 08:15