swift5.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)

//10.响应事件方法

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容