UIButton programmatically create callback for user action

Using Swift for iOS, how would I allow for a UIButton object which I create programmatically to respond to a user action without using Interface Builder?

Answered by Frameworks Engineer in 250827022

Hi Shinehah


Once you have instantiated your button, you can call addTarget(_:action:for:) to associate a method in one of your object's that should be called for any of the button's control-events. Typically, touchUpInside is the control event you want to listen for.

Accepted Answer

Hi Shinehah


Once you have instantiated your button, you can call addTarget(_:action:for:) to associate a method in one of your object's that should be called for any of the button's control-events. Typically, touchUpInside is the control event you want to listen for.

UIButton programmatically create callback for user action
 
 
Q