Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make UIButton respond to touch on the transparent areas of a PNG image?

UIButton ignores touch if you touch it where there's no image alpha. Can I change it to respond to touch on its entire bounds?

like image 997
Anthony Frizalone Avatar asked Jun 28 '13 15:06

Anthony Frizalone


1 Answers

UIButton ignores touch if you touch it where there's no image alpha. Can I change it to respond to touch on its entire bounds?

One easy way that I think still works is to set the background color to something that's only mostly transparent. An alpha that's very small but still greater than 0.1 should look transparent but still respond to touches.

Otherwise, yes, you can override -hitTest:withEvent: such that it returns YES even if the touched area is transparent.

like image 132
Caleb Avatar answered Nov 05 '22 10:11

Caleb