Why doesn't UIButton showsTouchWhenHighlighted work when the button is on a UITableViewCell?

ε祈祈猫儿з 提交于 2020-01-02 14:02:26

问题


I put a UIButton on a UITableViewCell and set its showsTouchWhenHighlighted property to YES. The cell's selection style is UITableViewCellSelectionStyleNone. I have a selector that gets called when the button is tapped and it's working fine, so the button is getting the touch events fine. However, button doesn't show the highlight effect when touched.

When I put this button on a UIView, the highlight effect works.

How can I make this work when the button is placed on the cell?


回答1:


Are you adding the button to the cell or cell.contentView? The contentView property behaves more like a regular UIView, that might solve your problem.




回答2:


You need to set 'delaysContentTouches' to NO on the Table View



来源:https://stackoverflow.com/questions/14756792/why-doesnt-uibutton-showstouchwhenhighlighted-work-when-the-button-is-on-a-uita

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!