I have an UIImageView(image loaded from remote server at runtime), now i want to open a specific url(say http://www.google.com) by clicking on this image. i have done this by clicking on button, but i dont know how to do that with imageView.
any suggestion or sample code will be appreciated.
Thanks!!
In interface builder (or in your storyboard), select your UIImageView.
Control-dragfrom the image to the header file of your class. Select “action”, and name it as you want. This will add something likein your header, and
in your .m file. Insert whatever code you need in this function, and I think you’re good to go !
Let me know if you worked your way through.
EDIT : Oops, seems like I talked a bit too quickly, this won’t work as you can’t add an action to a UIImageView. Another edit coming soon.
EDIT #2 :
Okay, first make sure your image view is “user interaction enabled” in the xib or on your storyboard. Then add an outlet for the image by control-dragging your UIImageView on your header file. Then use the UIResponder methods touchesBegan, touchesMoved, touchesEnded (and so on) to detect the touch on the image view : add this to your .m file :