RayChen
RayChen

Reputation: 1468

Why UIButton can't stay selected state when disable?

I have a UIButton which is set different images for normal and selected state.

I find that when I disable the button by setting button.enable = NO, even previous is selected state, the button will turn to normal state image, But I po the button selected value which is still YES.

How can I keep using selected image when button is disable? Is that the only way by changing normal state image when button change enable value?

Upvotes: 0

Views: 573

Answers (2)

Nadzeya
Nadzeya

Reputation: 651

In Swift:

let state = UIControl.State.selected.union(UIControl.State.disabled)

Upvotes: 0

Julian
Julian

Reputation: 9337

Set the image for the case when button is Selected and Disabled as this is a different state that the solely other state. Set the image but for state like this:

UIControlStateSelected | UIControlStateDisabled

Control's state can be a combination of a few states from the list :)

As a nice lesson you can log changes of a control's state and see combinations of states it will gets in different cases.

Upvotes: 2

Related Questions