How to make a UILabel clickable? How to make a UILabel clickable? ios ios

How to make a UILabel clickable?


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


Swift 3 Update

Replace

Selector("tapFunction:")

with

#selector(DetailViewController.tapFunction)

Example:

class DetailViewController: UIViewController {    @IBOutlet weak var tripDetails: UILabel!    override func viewDidLoad() {        super.viewDidLoad()        ...        let tap = UITapGestureRecognizer(target: self, action: #selector(DetailViewController.tapFunction))        tripDetails.isUserInteractionEnabled = true        tripDetails.addGestureRecognizer(tap)    }    @objc    func tapFunction(sender:UITapGestureRecognizer) {        print("tap working")    }}


SWIFT 4 Update

 @IBOutlet weak var tripDetails: UILabel! override func viewDidLoad() {    super.viewDidLoad()    let tap = UITapGestureRecognizer(target: self, action: #selector(GameViewController.tapFunction))    tripDetails.isUserInteractionEnabled = true    tripDetails.addGestureRecognizer(tap)}@objc func tapFunction(sender:UITapGestureRecognizer) {    print("tap working")}