// 按钮 button
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 300, 50, 30);

// button.backgroundColor = [UIColor redColor];

// 设置标题
// 参数1 : 标题内容
// 参数2 : 显示标题的状态

// [button setTitle:@"登录" forState:UIControlStateNormal];
// [button setTitle:@"都比" forState:UIControlStateSelected];

// 设置标题颜色

// [button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];

// 设置标题字体大小

//button.titleLabel.font = [UIFont boldSystemFontOfSize:25];

// 前景图和背景图的区别
// 1. 前景图保留图片原本尺寸, 背景图是填充到button中
// 2. 前景图将标题文字挤到右边, 背景图文字在图片上
// 3. 前景图多应用于显示很小"地盘"很大的场景

// 设置背景图片
// 注意, 系统的选择状态判断依赖于系统的seleted属性
// 需要手动改变selected
[button setBackgroundImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"checked"] forState:UIControlStateSelected];
// 设置前景图片
// 需要渲染(无楼空)

// [button setImage:[UIImage imageNamed:@"checked@2x.png"] forState:UIControlStateNormal];


// 重要方法, 给button注册处理方法
// 按下并抬起时生效
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

屏幕快照 2016-01-14 下午9.04.52.png
屏幕快照 2016-01-14 下午9.05.12.png