1.最简单的一个创建方式
UIButton *btn = [[UIButton alloc] init];
2.常用创建方式,在创建button的同时设置type
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
3.设置button的文字
在使用中需要注意title的默认颜色是无色的接下来需要设置下title的颜色
参数一:文字
参数二:Button的状态
常用状态:
默认(UIControlStateNormal)
高亮(UIControlStateHighlighted)
禁用(UIControlStateDisabled)
[btn setTitle:@"巴拉巴拉巴拉" forState:UIControlStateDisabled];
4.设置button title的字体颜色
参数一: UIColor 需要传入一个UIColor (字体的颜色)
参数二:button的状态
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
5. 设置button的背