views:

71

answers:

2

How can I add a UIButton in a CALayer and hookup the touch event?

A: 

In iOS, all UIViews own and draw themselves through a CGLayer. You probably want to create a UIView for your button to go in. Everything you can do with raw CGLayers, you can do with UIViews.

David M.
A: 

A CALayer is not an event responder, so trying to hook it up to a touch event handler will do nothing.

If you want a button that actually works on top of a CALayer, put that CALayer into a UIView (which is a subclass of UIResponder), and add a UIButton to that view (so it can get added to the event response chain).

hotpaw2