UIView ClickListener : Swift

This post was originally posted at https://agrawalsuneet.github.io/blogs/uiview-clicklistener-swift/ and reposted on Medium on 14th Dec 2020.
//swift code in view controller

let gesture = UITapGestureRecognizer(target: self, action: #selector(self.clickAction(sender:)))
self.myView.addGestureRecognizer(gesture)

func clickAction(sender : UITapGestureRecognizer) {
// Do what you want
}
class ClickListener: UITapGestureRecognizer {
var onClick : (() -> Void)? = nil
}

Please continue reading at https://agrawalsuneet.github.io/blogs/uiview-clicklistener-swift/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store