views:

1329

answers:

3

I have programatically added a UIImageView. How do I make it send a message to my controller when the users clicks it, sending itself as the only parameter?

+3  A: 
  1. Create a new class that extends UIImageView and use that.
  2. In your class, override the touch events - touchesBegan, touchesEnded and/or touchesMoved as appropriate
  3. From those methods, call back to a method on the controller.
Eric Petroelje
You also have to set the userInteractionEnabled property to YES.
Chris Lundie
+3  A: 

I'd just put a custom button over the UIImage view, and use normally - buttons with Custom style are invisible and so will not obscure the image. It's also a great way to turn regions of text into clickable areas as well.

Or, you could assign the custom image as a graphic background for the button.

Kendall Helmstetter Gelner
+5  A: 

I wouldn't use a UIImageView unless there was some other compelling reason. I'd just use a custom UIButton and use the UIImage as its background.

Tom Harrington