UIControl

96
无邪8
2018.05.21 14:58* 字数 1469

一、简介

<<UIControl是UIView的子类,当然也是UIResponder的子类。UIControl是诸如UIButton,UISwitch,UItextField等控件的父类,它本身包含了一些属性和方法,但是不能直接使用UIControl类,他只是定义了子类都需要使用的方法

<<继承关系:UIControl-->UIView-->UIResponder-->NSObject

格式为

1-->初始化(作用)

typedef NS_OPTIONS(NSUInteger, UIDataDetectorTypes) {

UIDataDetectorTypePhoneNumber                                        = 1 << 0, //检测电话

UIDataDetectorTypeLink                                              = 1 << 1, //检测网址和邮箱

UIDataDetectorTypeAddress NS_ENUM_AVAILABLE_IOS(4_0)                = 1 << 2, // 检测地址

UIDataDetectorTypeCalendarEvent NS_ENUM_AVAILABLE_IOS(4_0)          = 1 << 3, // 检测日历

UIDataDetectorTypeShipmentTrackingNumber NS_ENUM_AVAILABLE_IOS(10_0) = 1 << 4, // 货物追踪号码检测

UIDataDetectorTypeFlightNumber NS_ENUM_AVAILABLE_IOS(10_0)          = 1 << 5, // 班机号码检测

UIDataDetectorTypeLookupSuggestion NS_ENUM_AVAILABLE_IOS(10_0)      = 1 << 6, //用户可能要查找的信息

UIDataDetectorTypeNone          = 0,              // 禁用检测

UIDataDetectorTypeAll          = NSUIntegerMax   // 检测所有类型链接

} __TVOS_PROHIBITED;

;(如果属性有枚举类型的话,这里会有枚举类型说明

@property (nonatomic) UIDataDetectorTypes dataDetectorTypes NS_AVAILABLE_IOS(3_0);// 设置提示文字    (这是说明

二、UIControl的文本属性(属性的顺序与苹果API一致)

1-->控制控件触摸事件

@property(nonatomic,getter=isEnabled) BOOL enabled; // 默认是 YES,要禁用控件,可以将enabled属性设置为NO,这将导致控件忽略任何触摸事件。被禁用后,控件还可以用不同的方式显示自己,比如变成灰色不可用

2-->设置该UIControl 控件是否被选中

@property(nonatomic,getter=isSelected) BOOL selected; //默认是 NO

3-->设置控件的高亮状态

@property(nonatomic,getter=isHighlighted) BOOL highlighted; // 默认是NO. 当触摸进入/退出时,它会自动被设置/清除。

4-->设置控件在垂直方向上如何布置自身的内容

typedef NS_ENUM(NSInteger, UIControlContentVerticalAlignment) {  

UIControlContentVerticalAlignmentCenter  =0,   // 居中对齐  

UIControlContentVerticalAlignmentTop     =1,   // 顶端对齐  

UIControlContentVerticalAlignmentBottom  =2,   // 底端对齐  

UIControlContentVerticalAlignmentFill    =3,   // 填满整个控件  

}; 

@property(nonatomic) UIControlContentVerticalAlignment contentVerticalAlignment; //默认为 UIControlContentVerticalAlignmentCenter 居中

5-->设置控件在水平方向上如何布置自身的内容

typedef NS_ENUM(NSInteger, UIControlContentHorizontalAlignment) {  

UIControlContentHorizontalAlignmentCenter =0,   // 居中对齐  

UIControlContentHorizontalAlignmentLeft   =1,   // 左端对齐  

UIControlContentHorizontalAlignmentRight  =2,   // 右端对齐  

UIControlContentHorizontalAlignmentFill   =3,   // 填满整个控件  

}; 

@property(nonatomic) UIControlContentHorizontalAlignment contentHorizontalAlignment; //默认为 UIControlContentHorizontalAlignmentCenter居中

6-->当前webview加载内容位置的url请求

NSURLRequest* request =webView.request;

@property (nullable, nonatomic, readonly, strong) NSURLRequest *request;

7-->effectiveContentHorizontalAlignment

@property(nonatomic, readonly) UIControlContentHorizontalAlignment effectiveContentHorizontalAlignment;

8-->获取控件的状态

typedef NS_OPTIONS(NSUInteger, UIControlState) {  

UIControlStateNormal       =0,        //   普通状态  

UIControlStateHighlighted  =1 << 0,   //   高亮状态  

UIControlStateDisabled     =1 << 1,   //   选中状态  

UIControlStateSelected     =1 << 2,   //   禁用状态  

UIControlStateFocused NS_ENUM_AVAILABLE_IOS(9_0) = 1 << 3,  // 聚焦状态    

UIControlStateApplication  =0x00FF0000,   //   当用作应用标志时  

UIControlStateReserved     =0xFF000000    //   内部框架预留,无意义  

};

@property(nonatomic,readonly) UIControlState state; // could be more than one state (e.g. disabled|selected). synthesized from other flags.

9-->获取用户是否触及视图内容

@property(nonatomic,readonly,getter=isTracking) BOOL tracking;

10-->判断当前触摸点是否在控件区域类

@property(nonatomic,readonly,getter=isTouchInside) BOOL touchInside; // valid during tracking only

11-->用户开始触碰时激发

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(nullable UIEvent *)event;

12-->用户连续触碰时激发

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(nullable UIEvent *)event;

13-->用户结束触碰时激发

- (void)endTrackingWithTouch:(nullable UITouch *)touch withEvent:(nullable UIEvent *)event; // touch is sometimes nil if cancelTracking calls through to this

14-->监测到取消触摸事件

- (void)cancelTrackingWithEvent:(nullable UIEvent *)event; // event may be nil if cancelled for non-event reasons, e.g. removed from window

15-->添加 目标-动作对为不同的事件类型

typedef NS_OPTIONS(NSUInteger, UIControlEvents) {  

UIControlEventTouchDown                =1 <<  0,     // 单点触摸事件,用户触摸屏幕时  

UIControlEventTouchDownRepeat          =1 <<  1,     // 多点触摸事件,用于第二、第三根手指触摸时  

UIControlEventTouchDragInside          =1 <<  2,     // 触摸在控件窗口内拖动时  

UIControlEventTouchDragOutside         =1 <<  3,     // 触摸在控件窗口外拖动时  

UIControlEventTouchDragEnter           =1 <<  4,     // 触摸在窗口之外拖动到窗口内部时  

UIControlEventTouchDragExit            =1 <<  5,     // 触摸在窗口之内拖动到窗口外部时  

UIControlEventTouchUpInside            =1 <<  6,     // 在控件之内的触摸抬起时  

UIControlEventTouchUpOutside           =1 <<  7,     // 在控件之外的触摸抬起时  

UIControlEventTouchCancel              =1 <<  8,     // 触摸事件取消(例如正在触摸时有电话打进来)  

UIControlEventValueChanged             =1 << 12,     // 当控件的值在发生改变时,用于滑块、分段控件、以及娶她取值控件  

UIControlEventPrimaryActionTriggered NS_ENUM_AVAILABLE_IOS(9_0) = 1 << 13, // semantic action: for buttons, etc.  

UIControlEventEditingDidBegin          =1 << 16,     // 当文本控件开始编辑时,用于 UITextField  

UIControlEventEditingChanged           =1 << 17,     // 当文本控件的文本被改变时,用于 UITextField  

UIControlEventEditingDidEnd            =1 << 18,     // 当文本控件结束编辑时,用于 UITextField  

UIControlEventEditingDidEndOnExit      =1 << 19,     // 当文本控件内通过按下回车键结束编辑时  

UIControlEventAllTouchEvents           =0x00000FFF,  // 通知所有关于触摸的事件  

UIControlEventAllEditingEvents         =0x000F0000,  // 通知所有关于文本编辑的事件  

UIControlEventApplicationReserved      =0x0F000000,  // range available for application use  

UIControlEventSystemReserved           =0xF0000000,  // range reserved for internal framework use  

UIControlEventAllEvents                =0xFFFFFFFF   // 通知所有事件  

};  

- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

16-->删除 目标-动作对为不同的状态

- (void)removeTarget:(nullable id)target action:(nullable SEL)action forControlEvents:(UIControlEvents)controlEvents;

17-->)获取所有的目标集合

@property(nonatomic,readonly) NSSet *allTargets;

18-->获取所有的事件类型

@property(nonatomic,readonly) UIControlEvents allControlEvents; // list of all events that have at least one action

19-->获取某个target对象及事件相关的所有action

- (nullable NSArray *)actionsForTarget:(nullable id)target forControlEvent:(UIControlEvents)controlEvent; // single event. returns NSArray of NSString selector names. returns nil if none

20-->传递事件消息,是监听到事件后最先调用的方法,并且它是随着事件的重复产生而频繁调用的

- (void)sendAction:(SEL)action to:(nullable id)target forEvent:(nullable UIEvent *)event;

21-->发送相应通知,通过控件的代码可以指定时间目标,这个通知将被传播到这些指定的目标

- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents; // send all actions associated with events

ios-UIResponder开发控件