1
votes

I have a subclass of a UIButton:

    import UIKit
    class CustomButton: UIButton {

        required init?(coder decoder: NSCoder) {
            super.init(coder: decoder)

            //Customizing the button appearance
        }
    }

In interface builder, in storyboards, under my main view controller, I dragged and dropped a stock button, and changed it's 'Custom Class' to CustomButton from the drop down menu.

Wired it's 'Touch Up Inside' event to an IBAction.

Custom code for appearance shows up, but the button is not firing the 'Touch Up Inside'.

When I checked for touch events (touch began, ended, eat) within the subclass, the button seems to be receiving touch.

2

2 Answers

6
votes

Try disabling user interaction on the subviews that are part of your UIButton. This will allow the gestures to continue through to the button itself.

userInteractionEnabled = false
0
votes

Found the issue:

When I customize the button, I added a UIVisualEffectView as its subview that covered the whole frame, and that canceled the any events the button was able to take. Quite unfortunate.

I had to go with a UIView subclass and add a tap gesture to mimic the touch events.