Roman Roman - 2 months ago 5
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?


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()