常用的属性
UIButtonType
- UIButtonTypeCustom
- UIButtonTypeRounedRect 一个圆角矩形样式的按钮
- UIButtonTypeDetailDisclosure 一个详细纰漏按钮
- UIButtonTypeInfoLight 一个信息按钮,有一个浅色背景
- UIButtonTypeInfoDark 一个信息按钮,有一个黑暗的背景
- UIButtonTypeContactAdd 一个联系人添加按钮
按下按钮后出发一个事件
-(void)testUIButton1{
UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"危险!请勿触摸!" forState:UIControlStateNormal];
[button sizeToFit];
[button addTarget:self action:@selector(buttonDidPush) forControlEvents:UIControlEventTouchUpInside];
button.center = self.view.center;
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:button];
}
在屏幕中显示不同的按钮