1.创建UIButton 跟其他方式不同,不是直接alloc,init 创建 用工厂化方式创建
UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeSystem];//选择Button 的样式 系统给定的
//按钮的位置
sureBtn.frame = CGRectMake(60, 600, 300, 30);
//设在按钮背景颜色
sureBtn.backgroundColor = [UIColor blueColor];
//设置按钮正常状态的文字
[sureBtn setTitle:@"点击了" forState:UIControlStateNormal];
//设置正常状态的颜色
[sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//按钮选中状态
[sureBtn setTitle:@"被点击了" forState:UIControlStateSelected];
[sureBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
// 设置圆角的半径
sureBtn.layer.cornerRadius = 10;
sureBtn.clipsToBounds = YES;
// 按钮所要做的事件
[sureBtn addTarget:self action:@selector(sureButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
//添加到视图控制区
[self.view addSubview:sureBtn];