Which is better, setEnabled or setUserInteractionEnabled?

后端 未结 2 1787
名媛妹妹
名媛妹妹 2020-12-17 16:16

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

相关标签:
2条回答
  • 2020-12-17 16:47

    if something is disabled it is grayed out.

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

    0 讨论(0)
  • 2020-12-17 16:48

    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. Hence using enabled is more conventional.

    0 讨论(0)
提交回复
热议问题