Swift 5
In my case I needed access to the UILabel that was clicked, so you could do this inside the gesture recognizer.
let label:UILabel = gesture.view as! UILabel
The gesture.view property contains the view of what was clicked, you can simply downcast it to what you know it is.
@IBAction func tapLabel(gesture: UITapGestureRecognizer) {
let label:UILabel = gesture.view as! UILabel
guard let text = label.attributedText?.string else {
return
}
print(text)
}
So you could do something like above for the tapLabel function and in viewDidLoad put...
<Label>.addGestureRecognizer(UITapGestureRecognizer(target:self, action: #selector(tapLabel(gesture:))))
Just replace <Label>
with your actual label name