Creating an irregular UIButton in Swift where transparent parts are not tappable

前端 未结 2 925
谎友^
谎友^ 2021-01-07 04:17

I am making a pie chart where each sector is a separate button with a background image, but UIButton has a rectangular shape and all the buttons overlap. Is there a way to m

相关标签:
2条回答
  • 2021-01-07 05:02

    You can use UIBezierPath or CGPath to define your pie chart sections and use their containsPoint: or CGPathContainsPoint to detect touch

    0 讨论(0)
  • 2021-01-07 05:13

    As I'm concerned, may be the CAShapeLayer is better way to achieve the pie chart. By doing that, you can use

    [layer hitTest:] 
    

    method to deal with the touch action.

    0 讨论(0)
提交回复
热议问题