Search code examples
iphoneuibuttongeometryclickable-image

UIButton: Need a circle hit area


Ok I have 6 custom UIButtons. Their normal state image are all circles images. They are all spaced out equally but all the circles touch each other.

The problem with the custom UIbutton (which has a circle image on it), is that the hit area of that button is square, and the corners of this square overlaps the hitarea of the other custom button's hitarea.

How do i make the hit area of a UIbutton whos normal state has a circle image, be only clickable on that circle only, rather than the normal square hit area?!

I hope that someone can find a way for me to solve this problem that i currently am having!

Thanks in advance

Pavan


Solution

  • If the square area of a "circle" is clicked on, you should then check if the distance between the center of the circle and the coordinates of the click are less than the radius of the circle. If not, then the "hit" can be ignored.