Let’s say that you want to have buttons that are irregularly shaped, and there’s some reason that the standard hit testing which does not check image content is undesirable for some reason, like if you have overlapping buttons like this:
… well, first off, you should fix your interface. But let’s assume further that there actually is a good reason, like “you’re being paid” for instance, to implement something like the above: well, then, here is how to go about turning a button’s UIImage into a hit testing mask:
Irregularly Shaped UIButtons with update here linking to latest code.
There is an alternative implementation here, as well:
OBShapedButton: Non-rectangular buttons on the iPhone
So there you go. Even if you design sensible interfaces so this exact application isn’t of great interest to you, these implementations involve UIImage content dissection that could very well be of use in other situations, so the code’s worth a look.

0 Responses to “Irregular Buttons”
Leave a Reply