How to have a custom UIButton respond to taps only on nontransparent parts?
I have a UIButton whose type is custom, and is represented by a png file, part of which is transparent.
Naturally, I want my butt开发者_C百科on to activate the touchUpInside event if and only if the non transparent (=visible) part is tapped. But I get the event also when I touch the transparent part, which is unacceptable.
How can I make my button aware only of its visible part?
Strip your image into two parts. One that is the button (clickable-part) and one that is the background. Set the button images for only the clickable area. Place the UIButton on top of an UIImageView with the background on it. You can inherit from UIButton to make your own control that is a UIButtonWithBackground like above and then override the state functions to change the background state when the button changes state too.
精彩评论