swift5.0 UIButton

//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.響應事件方法

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容