Daniele B Daniele B - 1 year ago 198
Swift Question

Swift: how to make a UILabel clickable?

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() {
let tap = UITapGestureRecognizer(target: self, action: Selector("tapFunction:"))

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

Answer Source

Have you tried to set userInteractionEnabled to YES on the tripDetails label? This should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download