Hey everyone. I have a UIImageView that I want to receieve an action. I want it to act like a button. It will not have an image set so it will be invisible, then when tapped i want it to change to an image.
I know that IBActions do not work on a UIImageView. How could I achieve this?
P.S I don't want to set the image property of a button it must be a UIImageView.
Hey everyone. I have a UIImageView that I want to receieve an action. I want it to act like a button. It will not have an image set so it will be invisible, then when tapped i want it to change to an image.
I know that IBActions do not work on a UIImageView. How could I achieve this?
P.S I don't want to set the image property of a button it must be a UIImageView.
UIImageView inherits from UIControl - so look there to see how it can respond.
As far as I can see, you should not have to subclass UIImageView - just sent add another object as the target for any UIControlEventTouchUpInside events, using "addTarget:action:forControlEvents:"
There may be a technical reason why this does not work... but you can use a normal button and set it's type (top of the inspector) to custom, then just set your image to the BG.
Hey everyone. I have a UIImageView that I want to receieve an action. I want it to act like a button. It will not have an image set so it will be invisible, then when tapped i want it to change to an image.
I know that IBActions do not work on a UIImageView. How could I achieve this?
P.S I don't want to set the image property of a button it must be a UIImageView.
Replace it with a button in the drawRect statement.
Hey everyone. I have a UIImageView that I want to receieve an action. I want it to act like a button. It will not have an image set so it will be invisible, then when tapped i want it to change to an image.
I know that IBActions do not work on a UIImageView. How could I achieve this?
P.S I don't want to set the image property of a button it must be a UIImageView.
The default value for the userInteractionEnabled property of a UIImageView is NO. To make a UIImageView accept actions, you need to set the value of the property to YES.
I could use Touch events of the UIImageView programmartically, use a transparent button over the image, use a custom button with the image, etc.
However, I can't simply use the UIImageView with UserInteractionEnabled inside the Interface Builder and simply wire it to an IBAction. There is no IBAction I can wire the UIImageView to. Nor can I set the Class of it to UIControl. (Like for the background, I can change the class to UIControl and wire it to backgroundTouched action).
Since the UIImageView must have desended from UIVIew and UIView can be a UIControl, this does not make much sense, but that is how it is in the Interface Builder.