// 创建一个深色背景的提示信息按钮
let bt1 = UIButton(type: UIButtonType.infoDark)
bt1.frame = CGRect(x: 130, y: 80, width: 40, height: 40)
// 创建一个普通的圆角按钮
let bt2 = UIButton(type: UIButtonType.roundedRect)
bt2.frame = CGRect(x: 80, y: 180, width: 150, height: 44)
bt2.backgroundColor = UIColor.purple
bt2.tintColor = UIColor.yellow
bt2.setTitle("Tap Me", for: UIControlState())
bt2.addTarget(self, action: #selector(ViewController.buttonTap(_:)), for: UIControlEvents.touchUpInside)
let bt3 = UIButton(type: UIButtonType.roundedRect)
bt3.backgroundColor = UIColor.brown
bt3.tintColor = UIColor.white
bt3.setTitle("Tap Me", for: UIControlState())
bt3.frame = CGRect(x: 80, y: 280, width: 150, height: 44)
// 开启遮罩(不开启遮罩设置圆角无效)
bt3.layer.masksToBounds = true
// 设置圆角半径
bt3.layer.cornerRadius = 10
// 设置按钮边框宽度
bt3.layer.borderWidth = 4
// 设置按钮层边框颜色为浅灰色
bt3.layer.borderColor = UIColor.lightGray.cgColor
self.view.addSubview(bt1)
self.view.addSubview(bt2)
self.view.addSubview(bt3)
// 添加图片按钮
let bt1 = UIButton(type: UIButtonType.roundedRect)
let rect = CGRect(x: 31, y: 100, width: 257, height: 60)
bt1.frame = rect
let image = UIImage(named: "pic1")
bt1.setImage(image, for: UIControlState())
bt1.setTitle("Tap mE", for: UIControlState())
bt1.setTitleColor(UIColor.black, for: UIControlState())
bt1.titleLabel?.font = UIFont(name: "Arial", size: 24)
bt1.addTarget(self, action: #selector(ViewController.buttonTap(_:)), for: UIControlEvents.touchUpInside)
self.view.addSubview(bt1)