Recently, I was having an issue I was having with subviews added to my UIButton objects that I was customizing. The buttons would behave fine if they were standard rounded rect buttons, but the moment I added a UIView and some UILabels to it, the taps stopped responding.
But I was able to resolve it, thanks to the tip provided here:
The solution boils down to something very simple and it makes sense when you think about it, but at first it seems strange:
- All you need to do is set userInteractionEnabled and exclusiveTouch to NO on the items that you want to add as subviews to your UIButton (and don’t set those properties to NO for the UIButton itself).
Once you turn off user interaction and exclusive touch properties on the subviews, your events will be sent to the underlying button (or at least that’s how I like to think of it happening…).
I initially read the post wrong and set them to YES and couldn’t figure out why it wasn’t working. Then I went back and looked at the comments, which pointed out where I went wrong.
Hope this helps!