Swift adds a click gesture method to the control

  • 2020-05-06 11:43:22
  • OfStack

Today, a colleague asked me how to add the click method to headerview of tableview. Today, I will simply explain how to add the click gesture to swift :


imagepath.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "imagePathClick:"))

How about that? Does it look a lot simpler than oc? Just to explain,imagePath is an UIImageView that I defined. In fact, the reason is that you may not open user interaction, many controls, by default, do not accept user interaction, such as ImageView, such as Label

imagepath.userInteractionEnabled = true


Related articles: