我想让一个UILabel可点击。
我已经尝试过这个方法,但是它没有起作用:
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")
}
}
UILabel
的框架是什么?你确定你正在触摸标签的框架内吗?有没有其他UIViews
遮盖住标签?标签的userInteractionEnabled
属性设置为True
了吗? - JAL