UIButton with rounded corners allows you to interact in corners

I have a button that I create in Interface Builder. I set my angular radius and masks for applications in Interface Builder:

Runtime attributes

Essentially, these settings make the button round. This will fix my button correctly; however, angles are still interactive.

How can I make the interaction stay inside the layer?

Here is a screenshot of my button:

Button Screenshot

My button is a red circle. I set the light gray UIView behind it to show the area in which it still responds to touches.

+4
source share
2 answers

You can subclass UIButton;

in – (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event , , . : http://www.planet1107.net/blog/custom-shape-uibutton-tutorial/

... .. https://github.com/ole/OBShapedButton

update - @jancakes:

* github: , , ,

0

, backgroundColor . , UIImage .

, .

-1

Source: https://habr.com/ru/post/1533737/


All Articles