我有 UILabel,我想在“电子邮件”一词中添加 IBAction 以在 iPhone 中打开电子邮件客户端。这是我的代码:
func setInfoLabel() {
self.myLabel.text = "send me and email if you need more information"
}
你们中有人知道如何将 Action 添加到 UILabel 中的单词吗?
非常感谢您的帮助。
最佳答案
你应该使用 UIButton 而不是 UILabel 因为它只是为了显示文本而创建的,但是,如果你仍然想使用它
override func viewDidLoad() {
super.viewDidLoad()
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapAction))
self.myLabel.addGestureRecognizer(gestureRecognizer)
}
/* will be called when tapping on the label */
@objc func tapAction() -> Void {
}
关于iOS:将 IBAction 添加到 UILabel 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38275895/