简体   繁体   中英

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?

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.

在斯威夫特:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM