Difference between enabled and userInteractionEnabled properties

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也不能响应点击事件。

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-10 05:47:28

Difference between enabled and userInteractionEnabled properties的相关文章

ElasticSearch 基础(4) - Mapping

一.Mapping概述 为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成Full-text或者精确的字符串值. ES需要知道每个字段里面都包含了什么类型.这些类型和字段的信息存储(包含)在映射(mapping)中. 索引中每个文档都有一个类型(type).每个类型都拥有自己的映射(mapping)或者模式定义(schema definition). 一个映射定义了字段类型,每个字段的数据类型,以及字段被Elasticsearch处理的方式.映射还用于设置关联到类型上的元数据

ScrollView详解

创建方式 1:StoryBoard/Xib 这里StoarBoard就不多说,直接拖就可以,说太多没意思,如果连这个都不会我只能先给你跪了! 2:代码: 1 2 3 CGRect bounds = [ [ UIScreen mainScreen ] applicationFrame ] ; UIScrollView* scrollView = [ [UIScrollView alloc ] initWithFrame:bounds ]; 当你创建完滚动视图后,你可以将另一个视图的内容粘合到滚动视

iOS开发——UI篇&ScrollView详解

ScrollView详解 创建方式 1:StoryBoard/Xib 这里StoarBoard就不多说,直接拖就可以,说太多没意思,如果连这个都不会我只能先给你跪了! 2:代码: CGRect bounds = [ [ UIScreen mainScreen ] applicationFrame ] ; UIScrollView* scrollView = [ [UIScrollView alloc ] initWithFrame:bounds ]; 当你创建完滚动视图后,你可以将另一个视图的内

UI基础—— UIScrollView

一.UIScrollView使用的步骤 1.创建UIScrollView 2.将需要展示的内容添加到UIScrollView中 3.设置UIScrollView的滚动范围 (contentSize) 1 @interface ViewController () 2 @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; 3 @end 4 // 1.添加两个子控件到UIScrollView中 5 // 一个控件没有设置frame

IOS UI基础05

UIScrollView UIScrollView使用的步骤 1.创建UIScrollView 2.将需要展示的内容添加到UIScrollView中 3.设置UIScrollView的滚动范围 (contentSize) 注意: 如果想让UIScrollView进行滚动, 必须设置可以滚动的范围 scrollView不能滚动的几种情况 1.没有设置contentSize 2.scrollEnabled属性 = NO 3.userInteractionEnabled属性 = NO enabled和

Infragistics 汉化

Infragistics 汉化实例: Infragistics.Shared.ResourceCustomizer rc=Infragistics.Win.UltraWinGrid.Resources.Customizer; rc.SetCustomizedString("SummaryDialogAverage", "平均"); rc.SetCustomizedString("SummaryDialogCount", "总数"

[MS SQL Server]SQL Server如何开启远程访问

在日常工作中,经常需要连接到远程的MS SQL Server数据库中.当然也经常会出现下面的连接错误. 解决方法: 1. 设置数据库允许远程连接,数据库实例名-->右键--->属性---Connections---->勾选 Allow remote connections to this server. 2. 开启TCP/IP协议: Sql Server Configuration Manager---> Protocols for SQLEXPRESS ---> TCP/I

Microsoft Win32 to Microsoft .NET Framework API Map

Microsoft Win32 to Microsoft .NET Framework API Map .NET Development (General) Technical Articles Microsoft .NET Framework and Microsoft Visual Studio User Education TeamsMicrosoft Corporation January 2004 Applies to:    Microsoft® .NET Framework ver

50 Excel VBA Oral Interview Questions

Ques 01. What is the difference between ByVal and ByRef and which is default ? Solution: ByRef: If you pass an argument by reference when calling a procedure the procedure access to the actual variable in memory. As a result the variable's value can