Set Action Listener Programmatically in Swift

前端 未结 2 390
别跟我提以往
别跟我提以往 2020-12-08 04:07

I saw some example codes that assign the same OnClick event to all the buttons in Android (even if they perform completely different action) . How can do it with Swift

2条回答
  •  囚心锁ツ
    2020-12-08 04:24

    Swift 4.*

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

    And the button triggers this function:

    @objc func didButtonClick(_ sender: UIButton) {
        // your code goes here
    }
    

提交回复
热议问题