如何使UILabel可点击? [英] How to make a UILabel clickable?
本文介绍了如何使UILabel可点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让UILabel可点击。
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")
}
}
推荐答案
你试过设置<在 tripDetails
标签上code> userInteractionEnabled 到 true
?这应该有效。
Have you tried to set userInteractionEnabled
to true
on the tripDetails
label? This should work.
这篇关于如何使UILabel可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文