UIButton Highlighted State not showing when clicking over a Selected UIButton

心已入冬 提交于 2019-12-04 05:04:49

The various states: UIControlStateNormal, UIControlStateSelected, and (UIControlStateSelected | UIControlStateHighlighted) are all actually distinct. If you want your shadowImage to apply both in the (only) highlighted state and in the highlighted+selected state, you must also set:

[button setBackgroundImage:shadowImage forState:(UIControlStateHighlighted | UIControlStateSelected)]

In swift this would be:

button.setBackgroundImage(shadowImage, forState: UIControlState.Selected.union(UIControlState.Highlighted))

In Swift v3 (Nov. 2016):

button.setBackgroundImage(shadowImage, for: UIControlState.selected.union(UIControlState.highlighted))

Swift 4.2

Applicable programmatically only.

aButton.setImage(UIImage(named: "your_image"), for: [.selected, .highlighted])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!