typedef NS_ENUM(NSInteger, UIButtonType) {
UIButtonTypeCustom = 0,
UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
UIButtonTypeRoundedRect = UIButtonTypeSystem,
};
简单操作
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.tag = 100;
button.frame = CGRectMake(30, 170, 200, 40);
[self.window addSubview:button];
[button setTitle:@"按钮" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
button.showsTouchWhenHighlighted = YES;
[button addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchUpInside];
- (void) buttonAction
{
NSLog(@"咔");
UIButton *btn = (UIButton *)[self.window viewWithTag:100];
[btn setTitle:@"点我" forState:UIControlStateNormal];
[btn removeTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
}
- (void) buttonAction:(UIButton *)sender
{
sender.backgroundColor = [UIColor redColor];
}