Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Non-square hit areas for buttons

I need to make some triangular buttons that overlap each other.

While UIButtons can take transparent images as backgrounds, and UIControls can have custom views, the hit area of these is always square. How can I create a triangular hitarea for my buttons?

I come from a FLash background so I would normally create a hitarea for my view, but I don't believe I can do this in Cocoa.

Any tips?

like image 555
Niall Mccormack Avatar asked Nov 27 '25 09:11

Niall Mccormack


1 Answers

You can achieve this by subclassing UIButton and providing your own:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    // return YES if point is inside the receiver’s bounds; otherwise, NO.
}

Apple's UIView Documentation provides the details, such as confirming that point is already in the receiver's coordinate system.

like image 136
odrm Avatar answered Nov 29 '25 01:11

odrm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!