介紹一個OC中的控件UIButton,顧名思義就是按鈕ide
UIButton*btn=[UIButton buttonWithType:(UIButtonType)];
UIButtonType是系統提供的,用來指定Button類型的枚舉字體
UIButtonTypeCustomspa
UIButtonTypeSystemcode
UIButtonTypeDetailDisclosureorm
UIButtonTypeInfoLight事件
UIButtonTypeInfoDarkget
UIButtonTypeContactAddit
2. 設置座標io
btn.frame=CGRectMake(0, 0, 10, 10);
3.設置編號select
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];