//1.創(chuàng)建
letbutton =UIButton(type:.custom)
button.frame=CGRect(x:200,y:200,width:70,height:40)
view.addSubview(button)
//2.設(shè)置標題
button.setTitle("呵呵", for: .normal)
button.setTitle("哈哈", for: .highlighted)
//3.選中
button.isSelected=false
//4.設(shè)置背景顏色
button.backgroundColor=UIColor.cyan
//5.設(shè)置背景圖片
button.setBackgroundImage(UIImage(named:"backImage"), for: .normal)
button.setBackgroundImage(UIImage(named:"backHightImage"), for: .highlighted)
//6.設(shè)置圖片
button.setImage(UIImage(named:"image"), for: .normal)
button.setImage(UIImage(named:"hightImage"), for: .highlighted)
//7.設(shè)置標題顏色
button.setTitleColor(UIColor.black, for: .normal);
button.setTitleColor(UIColor.red, for: .highlighted)
//8.設(shè)置標題文字大小
button.titleLabel?.font=UIFont.systemFont(ofSize:18)
//9.添加點擊響應事件
button.addTarget(self, action:#selector(buttonAction), for: .touchUpInside)

//10.響應事件方法