介绍一个OC中的控件UIButton,顾名思义就是按钮
- 初始化
UIButton*btn=[UIButton buttonWithType:(UIButtonType)];
UIButtonType是系统提供的,用来指定Button类型的枚举
UIButtonTypeCustom
UIButtonTypeSystem
UIButtonTypeDetailDisclosure
UIButtonTypeInfoLight
UIButtonTypeInfoDark
UIButtonTypeContactAdd
2. 设置坐标
btn.frame=CGRectMake(0, 0, 10, 10);
3.设置编号
btn.tag=0;
4 .设置标题
[btn setTitle:(nullable NSString *) forState:(UIControlState)];
在这里又出现一个枚举类型<#(UIControlState)#>
默认
UIControlStateNormal
高亮
UIControlStateHighlighted
不可点击状态
UIControlStateDisabled
已被选中状态
UIControlStateSelected
[btn setTitle:@"确定" forState:UIControlStateNormal];
[btn setTitle:@"取消" forState:UIControlStateHighlighted];
5.修改字体颜色
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
6 .增添点击事件
[btn addTarget:self action:@selector(selector) forControlEvents:(UIControlEvents)];
这里出现一个枚举类型(UIControlEvents),分别代表不同的点击手势
UIControlEventTouchDown
UIControlEventTouchDownRepeat
UIControlEventTouchDragInside
UIControlEventTouchDragOutside
UIControlEventTouchDragEnter
UIControlEventTouchDragExit
UIControlEventTouchUpInside
UIControlEventTouchUpOutside
7.设置字体大小
btn.titleLabel.font=[UIFont systemFontOfSize:12];