Guidance on making a UIImageView receive taps to change

Discussion in 'iOS Programming' started by macman7002, Feb 18, 2010.

  1. macman7002 macrumors regular

    Apr 28, 2008
    Hello there, sorry if this question has already been asked and answered. I tried a Google search but couldn't find anything on what I am trying to do for my skill level. I am new to iPhone developing and relatively new to Mac developing. But what I am looking to do is make a UIImageView change the the displayed image whenever a user taps the UIImageView. Does anyone know of any articles online about doing something like this? Or could anyone give me advice about how to do this?
    Thank you!!
  2. drf1229 macrumors regular


    Jun 22, 2009
    Ok, I think the best thing to do is to tell you what you need to do, not specifically the code that does it. First, you need to use TouchesBegan to capture the touch event. In that method, you need to change the UIImageView's image property to change the image. If you want the image to go in a sequence, you should create an integer to represent which image the ImageView will change to. Then, use a switch loop in your touchesBegan method to switch the image accordingly.
  3. macman7002 thread starter macrumors regular

    Apr 28, 2008
    Thank you drf1229!! I think this is the reading material I need! I really appreciate your help!
  4. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    You might want to consider using a UIButton with an image for a background view instead. Buttons are already designed to respond to taps and trigger methods.

Share This Page