Roman Roman - 1 year ago 107
iOS Question

Interaction of UIImageView and UITapGestureRecognizer in swift

I have several UIImageViews on my screen and if one of them is tapped, it has to change his color. As I had the same problem with UIView, the solution was:

func viewTapped(recognizer:UITapGestureRecognizer) {

viewTouched = recognizer.view as UIView!
thisCard.backgroundColor = UIColor.orangeColor()


But I haven't found the similar action for the image view. Could you help me?

Answer Source

You can change the tintColor of your UIImageViews :

func imageViewTapped(recognizer:UITapGestureRecognizer) {

    guard let imageView = recognizer.view as? UIImageView
      else { return }
    imageView.tintColor = UIColor.orangeColor()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download