Which is better, setEnabled or setUserInteractionEnabled?

穿精又带淫゛_ 提交于 2019-12-03 18:03:21

问题


I want to make a UIButton disable for user touch. Both setEnabled and setUserInteractionEnabled can do this. Which is better? How are they different?


回答1:


enabled is a property of UIControl, which is the superclass for UIButton. userInteractionEnabled is a property of UIView (which is the superclass of UIControl). enabled has effects on the visual state of the object (grayed out, by default) and is generally the preferred method of disabling a control—visual feedback indicating behaviors is a good thing.

There's not much practical upshot beyond that. Code that interacts with your controls is more likely to check if buttons are enabled than if their userInteractionEnabled property is set; it's more conventional.




回答2:


if something is disabled it is grayed out.

if interaction is disabled it appears normal but you can't interact with it.



来源:https://stackoverflow.com/questions/15649264/which-is-better-setenabled-or-setuserinteractionenabled

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