views:

367

answers:

2

Basically I have a custom UIButton and this custom button contains subviews. If I add those subviews to my uibutton, then the button stops responding to event changes. I.e if I click on it it doesn't respond to the selector. I have everything set as userInteractionEnabled. I also tried adding touchbegan and this is working. If I remove those subviews, the UIButton works again.

Any help would be greatly appreciated.

Cheers.

A: 

It seems that the subviews covers the button. If i make a huge frame for the button it seems to work if i click in the empty space. Any ideas?

+5  A: 

The subviews should have userInteractionEnabled set to NO. What is happening here is that the subviews are getting the touch events instead of the UIButton. If that doesn't work another option is to override hitTest:withEvent: in your custom UIButton so that it always returns itself and does not ask its subviews if they should handle the event. See the UIView docs for more details.

Jason Jenkins
Thanks a lot. You were right, i should not have userinteraction as enabled.