2

So, after finding my anwser in previos question here what I would like is to add GestureRecognizer on this UIImageView. When user tap, the color change. And when he tap again default image is restored.

Any tip to do that?

I was thinking about a List that I update in each click but not sure it is the best thing to do that.

here is the GestureRecognizer

UITapGestureRecognizer CreateTouchGesture(UIImageView imageView)
{
    var touchGesture = new UITapGestureRecognizer((tg) =>
    {
        imageView.Image = DrawSelectedBorder(imageView.Image);
    });

        return touchGesture;
}
Community
  • 1
  • 1
SunLiker67
  • 119
  • 6

1 Answers1

2

Based on comments, I can offer you this solution. You use UIImageView AnimationImages property to store you base image. And when you press again the image you retrieve it from this array. And to know in which state you are, you use Ighlighted property.

Like this :

var touchGesture = new UITapGestureRecognizer((tg) =>
{
    if(!imageView.Highlighted){
        imageView.Highlighted = true;
        imageView.AnimationImages = new UIImage[]{imageView.Image};
        imageView.Image = DrawSelectedBorder(imageView.Image);
    }else{
        imageView.Highlighted = false;
        imageView.Image = imageView.AnimationImages[0];
        System.Diagnostics.Debug.WriteLine(imageView.AccessibilityLabel);
    }
});
Leze
  • 739
  • 5
  • 24
  • Thanks again Leze, i would just wait if better solution came. Testing yours and it's working. Just wandering if it's memory safe to use it like this. I have many image to manage that way in my App. – SunLiker67 Apr 14 '17 at 12:14