I am showing multiple images in form of a grid in my content extension. how can I add an different action for every image. I know we can add action for button. Is it possible to add action for image too.
IOS : add action to image in content extension push notification
227 Views Asked by vk100 At
2
There are 2 best solutions below
0

For Swift 5 and for one image you can use easily this method.
override func viewDidAppear(_ animated: Bool) {
let gesture = UITapGestureRecognizer(target: self, action: #selector(touchImage))
self.imageView.isUserInteractionEnabled = true
self.imageView.addGestureRecognizer(gesture)
}
Then you need to put objc func in your class like below
@objc func touchImage() {
// write your code here when touch images
}
You can add a
UITapGestureRecognizer
to your image view and differentiate your images usingtags
like this:Objective-C Version:
Swift Version:
If you're trying to connect Obj-C to Swift. Add your
tags
in Obj-C and import your projects generated Swift header file in your Objective-C header file: