swift4.0 UIButton

//1.创建

letbutton =UIButton(type:.custom)

button.frame=CGRect(x:200,y:200,width:70,height:40)

view.addSubview(button)

//2.设置标题

button.setTitle("呵呵", for: .normal)

button.setTitle("哈哈", for: .highlighted)

//3.选中

button.isSelected=false

//4.设置背景颜色

button.backgroundColor=UIColor.cyan

//5.设置背景图片

button.setBackgroundImage(UIImage(named:"backImage"), for: .normal)

button.setBackgroundImage(UIImage(named:"backHightImage"), for: .highlighted)

//6.设置图片

button.setImage(UIImage(named:"image"), for: .normal)

button.setImage(UIImage(named:"hightImage"), for: .highlighted)

//7.设置标题颜色

button.setTitleColor(UIColor.black, for: .normal);

button.setTitleColor(UIColor.red, for: .highlighted)

//8.设置标题文字大小

button.titleLabel?.font=UIFont.systemFont(ofSize:18)

//9.添加点击响应事件

button.addTarget(self, action:#selector(buttonAction), for: .touchUpInside)

swift4.0 UIButton_第1张图片

//10.响应事件方法

你可能感兴趣的:(swift4.0 UIButton)