1、創建
/*
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
*/
UIButton *button = [UIButton buttonWithType:(UIButtonTypeSystem)];
2、位置大小
button.frame = CGRectMake(100, 100, 100, 30);
3、背景顏色
button.backgroundColor = [UIColor yellowColor];
4、文字及文字顏色
/*
UIControlStateNormal = 0,
UIControlStateHighlighted = 1 << 0, // used when UIControl isHighlighted is set
UIControlStateDisabled = 1 << 1,
UIControlStateSelected = 1 << 2, // flag usable by app (see below)
UIControlStateApplication = 0x00FF0000, // additional flags available for application use
UIControlStateReserved = 0xFF000000 // flags reserved for internal framework use
*/
[button setTitle:@"按鈕" forState:(UIControlStateNormal)];
[button setTintColor:[UIColor redColor]];
5、button的label屬性
// 後面文字大小、字體、倒角、陰影...都與UILable的屬性一致
button.titleLabel
6、點擊事件
//按下提示鬆開發送 --> touchDown
//鬆開提示發送成功 --> touchUpInSide
//向外滑出提示取消 --> touchDragExit
//往回滑提示鬆開發送 --> touchDragEnter
//在按鈕外鬆開提示取消發送 --> touchUpOutSide
[button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchDown];
7、禁用按鈕
button.enabled = NO;
8、設置已選中狀態
button.selected = YES;