-1

In iOS in Xcode, I dropped a tap gesture recognizer control onto a label, and control-dragged the tap gesture recognizer to create an interface builder action. When I tap the label, the interface builder action doesn't fire. Here is my code:

@IBAction func actionTapLabelInstrumentDropDown(_ sender: UITapGestureRecognizer) {

    print("actionTapLabelInstrumentDropDown")

    instrumentDropDown.show()

}

The print statement never prints.

daniel
  • 1,446
  • 3
  • 29
  • 65
  • 3
    Labels don't response to user interactions by default. You need to enable user interactions on the label. – rmaddy Apr 20 '19 at 15:38

1 Answers1

2

Writing an answer based on @rmaddy observations in comments under the question, just so it would be more visible to the community.

Labels don't response to user interactions by default. You need to enable user interactions on the label.


Adding my two cents:

If your UILabel is in Storyboard/NIB, you only need to check User Interaction Enabled checkbox in the right side menu.

If you are programmatically creating UILabel then you will need to call following function in order to enable it:

self.myLabel.userInteractionEnabled = true
Tomas Jablonskis
  • 4,246
  • 4
  • 22
  • 40