Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Custom shaped button using CALayer

Tags:

ios

what is the best way to achieve the following. enter image description here

Basically what I want to do is to create an "intractable area" where the user can touch and subsequent actions will take place. For example in the picture the user taps the green area a pop is presented with some options. Similarly there would be different colour "intractable areas or buttons" with in that pizza slice, if you may.

I was thinking of having buttons created through CALayer and try to fit them with in the bounds of the empty state image, but i don't know how to achieve this. Any other ideas are well appreciated. Empty state of the pizza slice

like image 396
Junaid Ahmed Avatar asked Sep 13 '26 15:09

Junaid Ahmed


1 Answers

I would subclass UIButton or UIControl to make your custom button. Then override pointInside:withEvent: to see if the touch event is within the correct region.

See these links for more info and ideas:

  • Non-Rectangular Buttons on iOS
  • Abusing UIView (see section on pointInside:withEvent:)
  • How to create a transparent window with non-rectangular buttons?
  • iPhone button with non-rectangle shape?
  • OBShapedButton
like image 56
Suragch Avatar answered Sep 16 '26 08:09

Suragch