UIControl:是一个 可以带有触发事件的 视图
1、UIControl 的字类(UIButton UISwitch UISegmentedControl UISlider UITextField UIPageControl)
这些视图 都可以点击 触发事件
UIButton按钮
UISwitch开关
UISegmentedControl 分段选择 控件
UISlider 滑杆
UITextField 文本框 文本输入控件
UIPageControl 页面控制(点点
UIButton:是一个按钮——>系统封装好的UIControl 里面可以放文字、图片 以及设置文字 图片 相关的内容 同时也可以触发事件
初始化;
1、button的初始化 有一个类方法
+ (instancetype)buttonWithType:(UIButtonType)buttonType;
UIButtonTypeCustom = 0, // no button type
UIButtonTypeSystem //系统默认的样式
NS_ENUM_AVAILABLE_IOS(7_0), // standard system button
UIButtonTypeDetailDisclosure, 显示详细信息的样式
UIButtonTypeInfoLight,高亮
UIButtonTypeInfoDark,灰暗
UIButtonTypeContactAdd,+
UIButtonTypeRoundedRect = UIButtonTypeSystem, // Deprecated, use UIButtonTypeSystem instead
UIControlState:状态
UIControlStateNormal 普通状态
UIControlStateHighlighted 高亮状态
UIControlStateDisabled 取消禁用状态
UIControlStateSelected 选中状态
UIControl常用属性:
1、enabled 启用 激活 用来设置视图 是否可以使用触发事件
默认值 是YES 如果设置成NO 就禁用这个视图的触发事件
2、selected:选中(状态) 是不是选中了这个控件 默认值 是NO
3、highlighted:高亮(状态)默认值是 NO
重要方法:
给视图 添加 相应事件的 方法
- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
1、Target :目标——>让谁去调用 一个方法
2、action:行动——>要让这个目标做什么事
3、SEL 是一个运行时——>@selecter()——>选择者(方法选择器)作用:用来选择一个方法
4、ControlEvents:控制事件——>执行 行动的方法