How to make a UILabel clickable?

Daniele B picture Daniele B · Nov 11, 2015 · Viewed 114.8k times · Source

I would like to make a UILabel clickable.

I have tried this, but it doesn't work:

class DetailViewController: UIViewController {

    @IBOutlet weak var tripDetails: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        let tap = UITapGestureRecognizer(target: self, action: Selector("tapFunction:"))
        tripDetails.addGestureRecognizer(tap)
    }

    func tapFunction(sender:UITapGestureRecognizer) {
        print("tap working")
    }
}

Answer

Claudiu Iordache picture Claudiu Iordache · Nov 11, 2015

Have you tried to set isUserInteractionEnabled to true on the tripDetails label? This should work.