Swift button click event, swiftbutton
Swift button click event
/// ViewController. swift // button // import UIKitclass ViewController: UIViewController {override func viewDidLoad () {super. viewDidLoad ()//?? SWIFT Advocates: // Replace 'selector ("buttonTap") 'with' # Selector (ViewController. buttonTap) '// click the button without the parameter let button = UIButton (frame: CGRect (x: 0, y: 0, width: 50, height: 30) button. backgroundColor = UIColor. yellow button. addTarget (self, action: # selector (ViewController. buttonTap), for: UIControlEvents. touchUpInside) // button1: Click the parameter "let button1 = UIButton (frame: CGRect (x: 100, y: 0, width: 50, height: 30)" button1.backgroundColor = UIColor. yellow button1.addTarget (self, action: # selector (buttonTap1 (button :)), for: UIControlEvents. touchUpInside) self. view. addSubview (button) self. view. addSubview (button1)} // selector is actually an Objective-C runtime concept @ objc func buttonTap () {print ("buttonTap")} @ objc func buttonTap1 (button: UIButton) {print ("buttonTap parameter ")}}