How to customize UILabel clickable

后端 未结 8 2095
余生分开走
余生分开走 2020-11-30 02:28

What I want:

In an iPhone app, I\'d like to show information in a tableView. In each cell, the text is like: John recently listen to music abcdefg.mp3. and if neede

8条回答
  •  Happy的楠姐
    2020-11-30 03:08

    Swift 4.2 Version:

    var labelView = UILabel()
    let gesture = UITapGestureRecognizer(target: self, action: #selector(userTappedOnLink))
    // if labelView is not set userInteractionEnabled, you must do so
    labelView.isUserInteractionEnabled = true
    labelView.addGestureRecognizer(gesture)
    
    
    @objc func userTappedOnLink() {
        print("clicked!")
    }
    

提交回复
热议问题