I have many UIButtons which are linked to codes, but I wanted to have a method which works for all UIbuttons without connecting the method to the button, to play a sound when each button is pressed. Is there a way to detect when a general UIbutton is pressed? even if not linked to any code?
Share
As mentioned in my comments, one option is by subclassing
UIButton. You can create a subclass ofUIButtonand implement itsinitmethods to add an action which will play a sound when pressed. This would be like the normal button actions but the target will be this custom subclass.Then use the button as,
If you are using xib or storyboard, you can change the class of button object from
UIButtontoCustomButton.