Swift 3.0
Inicialize o gesto para tempLabel
tempLabel?.text = "Label"
let tapAction = UITapGestureRecognizer(target: self, action: #selector(self.actionTapped(_:)))
tempLabel?.isUserInteractionEnabled = true
tempLabel?.addGestureRecognizer(tapAction)
Receptor de ação
func actionTapped(_ sender: UITapGestureRecognizer) {
// code here
}
Swift 4.0
Inicialize o gesto para tempLabel
tempLabel?.text = "Label"
let tapAction = UITapGestureRecognizer(target: self, action:@selector(actionTapped(_:)))
tempLabel?.isUserInteractionEnabled = true
tempLabel?.addGestureRecognizer(tapAction)
Receptor de ação
func actionTapped(_ sender: UITapGestureRecognizer) {
// code here
}
userInteractionEnabled = true