1,按钮的状态(state)
//按钮的正常状态
UIControlStateNormal
//按钮被点击是的状态
UIControlStateHighlighted
//按钮被禁止点击时的状态
UIControlStateDisabled
//按钮被点击后的状态
UIControlStateSelected
2给按钮添加标题(setTitle)并且说明是给什么状态下添加标题
[[UIButton alloc]initWithFrame:CGRectMake(40, 43, 200, 50)] setTitle:@"假设" forState: UIControlStateNormal];
同样的,给其设置图片(setImage) 设置字体颜(setTitleColor)等也能这么做.button的禁用 button.hidden = NO;
添加事件与响应方式 [listBtn addTarget:self action:@selector(listButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
// 设置前景图片
[_buttont setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
// 设置背景图片
[_buttont setBackgroundImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
//设置字体颜色
[_buttont setTitleColor:<#(nullable UIColor *)#> forState:<#(UIControlState)#>]```
3
***
> `设置此类类型的系统自定的特色按钮图片(https://img-blog.csdn.net/20180812101605806?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyODkxNzA5/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
UIButton*uib=[UIButton buttonWithType:UIButtonTypeContactAdd];
//按钮中的风格图片大小已固定不可改变,只能改变他的位置
uib.frame = CGRectMake(100, 100, 200, 50);
self.view addSubview:uib];`
***
self.loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_loginBtn.frame = CGRectMake(50, 200, self.view.frame.size.width-100, 50);
[_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
_loginBtn.backgroundColor = [UIColor grayColor];
_loginBtn.enabled = NO;
[self.view addSubview:_loginBtn];
//如何自己调试颜色 (通过测色计获得三元色的值,再分别除以255.0)
_loginBtn.backgroundColor = [UIColor colorWithRed:167/255.0 green:57/255.0 blue:61/255.0 alpha:1];
“`