Difference between enabled and userInteractionEnabled properties

原创 2015年07月08日 10:46:14



I read through the documentation, and here are my findings.

UIButton inherits from UIControl the boolean property enabled

A Boolean value that determines whether the receiver is enabled.

Specify YES to make the control enabled; otherwise, specify NO to make it disabled. The default value is YES. If the enabled state is NO, the control ignores touch events and subclasses may draw differently.

UIControl inherits from UIView the boolean property userInteractionEnabled:

A Boolean value that determines whether user events are ignored and removed from the event queue.

When set to NO, user events—such as touch and keyboard—intended for the view are ignored and removed from the event queue. When set to YES, events are delivered to the view normally. The default value is YES.

From this I conclude

  • button.userInteractionEnabled = NO means the button looks normal but doesn't respond to touches (from the UIView inheritance).

  • button.enabled = NO means the button is grayed out and doesn't respond to touches (from the UIControl inheritance). 


总的来说, userInteractionEnabled = NO,view看起来还是正常的,但是不能响应点击事件。

enabled = NO, view会变灰,如果有文字,文字也会变灰色。view也不能响应点击事件。


UIButton属性设置的优先级userInteractionEnabled,selected,enabled

UIButton属性设置的优先级userInteractionEnabled,selected,enabled
  • opentogether
  • opentogether
  • 2016年04月28日 10:40
  • 867

【iOS开发-56】案例BUG:按钮的enabled、控件的userInteractionEnabled以及两种提示框UIAlert和UIActionSheet

以下语句的原理在于:如果我们正在回答的时最后一道题,那么答对之后,它会继续调用nextQuestion方法,这个时候我们就判断它是否是最后一道题,如果是,则弹框。...
  • wsb200514
  • wsb200514
  • 2014年10月18日 21:28
  • 1592

btn的enabled和userInteractionEnabled

1.     btn.enabled = YES; btn.userinteractionEnabled = NO; 点击btn触发touchBegan(说明btn没有处理事件) 2.     ...
  • globalYK
  • globalYK
  • 2016年04月11日 23:19
  • 635

关于UIButton不改变title的问题(enable与userInteractionEnabled)

// 在发短信的界面中遇到一个问题,点击了发送短信,将发送短信的按钮设置为disable的状态,如下 sendMsgBtn.enabled = NO; //然后在倒计时中的方法为 seconds --...
  • hulala_wuqiang
  • hulala_wuqiang
  • 2016年09月26日 17:25
  • 507

The difference between the request time and the current time is too large.

报错信息: [Error Code]:RequestTimeTooSkewed, [Message]:The difference between the request time and the ...
  • hraceo
  • hraceo
  • 2017年01月09日 11:07
  • 1006

The Differences Between Java, C And C++

if (!window.netshel_ord) { netshel_ord=Math.random()*10000000000000000;}if (!window.netshel_tile) { ...
  • jianxiong8814
  • jianxiong8814
  • 2007年09月25日 12:21
  • 1175

What's the difference between C++ and Python

In Principle 1. C++ is a "statically typed" language, while Python is a "dynamically typed" languag...
  • bachelorchen
  • bachelorchen
  • 2015年07月20日 11:07
  • 210

[Error Code]:RequestTimeTooSkewed, [Message]:The difference between the request time and the current

在做备份的时候,一直出现RequestTimeTooSkewed错误,发现是自己虚拟机的时间不对; [root@localhost ~]# date Fri Sep 22 13:57:42 EDT 2...
  • Love_Taylor
  • Love_Taylor
  • 2017年09月25日 11:05
  • 477

OSS存储上遇到The difference between the request time and the current time is too large.

问题截图: 亲测有效!!! The difference between the request time and the current time is too large.(有道翻译:...
  • lilian1131
  • lilian1131
  • 2018年01月26日 12:59
  • 78

【JS】The differences between 基本类型 and 引用类型

5个基本数据类型:Undefined、Null、Boolean、Number、String;引用类型:var person = new Object();这里的person就是一个引用类型的变量,他的...
  • qq_27359091
  • qq_27359091
  • 2016年06月03日 22:08
  • 410
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Difference between enabled and userInteractionEnabled properties
举报原因:
原因补充:

(最多只允许输入30个字)