I want to make a UIButton
disable for user touch. Both setEnabled
and setUserInteractionEnabled
can do this. Which is better? How are they different?
我想为用户触摸设置UIButton禁用。 setEnabled和setUserInteractionEnabled都可以执行此操作。哪个更好?他们有什么不同?
2 个解决方案
#1
17
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.
enabled是UIControl的一个属性,它是UIButton的超类。 userInteractionEnabled是UIView的属性(它是UIControl的超类)。 enabled对对象的可视状态有影响(默认为灰色),通常是禁用控件的首选方法 - 视觉反馈表明行为是一件好事。
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.
除此之外没有太多实际的结果。与控件交互的代码更有可能检查按钮是否已启用,而不是设置了userInteractionEnabled属性;它更传统。
#2
6
if something is disabled it is grayed out.
如果某些东西被禁用,它会变灰。
if interaction is disabled it appears normal but you can't interact with it.
如果禁用交互,则表示正常,但您无法与之交互。
#1
17
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.
enabled是UIControl的一个属性,它是UIButton的超类。 userInteractionEnabled是UIView的属性(它是UIControl的超类)。 enabled对对象的可视状态有影响(默认为灰色),通常是禁用控件的首选方法 - 视觉反馈表明行为是一件好事。
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.
除此之外没有太多实际的结果。与控件交互的代码更有可能检查按钮是否已启用,而不是设置了userInteractionEnabled属性;它更传统。
#2
6
if something is disabled it is grayed out.
如果某些东西被禁用,它会变灰。
if interaction is disabled it appears normal but you can't interact with it.
如果禁用交互,则表示正常,但您无法与之交互。