最为最基本的控件,我们必须对button的每个常用属性都熟练应用;
1,使用之前,必须对按钮进行定义,为乐规范,在@interface ViewController (){}中进行定义,先定义后使用。
UIButton *_button1; 在实际的项目开发中,变量名尽可能长一点,并且在变量名前加"_" 下划线字符(规范)
2,接下来在@implementation ViewController中对按钮的属性进行赋值
_button1=[UIButton buttonWithType:UIButtonTypeRoundedRect]; //设置按钮的样式
UIButtonTypeCustom = 0, 自定义风格
UIButtonTypeRoundedRect, 圆角矩形
UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用
UIButtonTypeInfoLight, 亮色感叹号
UIButtonTypeInfoDark, 暗色感叹号
UIButtonTypeContactAdd, 十字加号按钮
3,为按钮设置背景颜色
_button1.backgroundColor=[UIColor whiteColor];
4,设置按钮在图中的显示位置和大小
_button1.frame=CGRectMake(100, 100, 40, 40);
5,给按钮起名字和名字的颜色
[_button1 setTitle:@"点击