Button create swift

override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(frame: CGRect(x: 100, y: 500, width: 100, height: 50))
button.backgroundColor = .green
button.setTitle("Test Button", for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)

self.view.addSubview(button)

}
func buttonAction(sender: UIButton!) {
print("Button tapped")
}
Previous
Next Post »