美文网首页
Swift 3.X按钮的创建及常用属性

Swift 3.X按钮的创建及常用属性

作者: NSLogForiOS | 来源:发表于2016-12-16 23:25 被阅读121次

///Button的创建及常用属性

///Button的创建

let button:UIButton = UIButton.init(type: UIButtonType.custom)

///创建Button的大小

button.frame = CGRect(x:20,y:100,width: 60,height:30)

///设置Button文字

button.setTitle("按钮", for: UIControlState.normal)

///设置Button文字颜色

button.setTitleColor(UIColor.red, for: UIControlState.normal)

///设置Button文字高亮

button.setTitle("高亮", for: UIControlState.highlighted)

///设置button文字选中状态

button.setTitle("选中", for: UIControlState.selected)

///设置button文字的背景颜色

button.backgroundColor = UIColor.purple

///设置button的背景图片

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

///添加按钮点击事件

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

self.view.addSubview(button)

相关文章

网友评论

      本文标题:Swift 3.X按钮的创建及常用属性

      本文链接:https://www.haomeiwen.com/subject/blromttx.html