iOS:将 IBAction 添加到 UILabel 的一部分

标签 ios swift uilabel

我有 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/

相关文章:

iphone - 如何让iPhone中的两个导航栏重叠?

ios - 从嵌入的 tableviewcontroller 中执行Segue时如何保留NavigationController

ios - 使用计时器更改 UILabel 的文本

objective-c - 适合 UILabel 中的文本

iOS - 从 UIImage 检索 EXIF UserComment

ios - 在 iOS 中使用 UIBezierPath 剪辑 UIView

ios - 如何制作两个segue函数?

swift - 为什么要在模型中使用私有(private)变量?

xcode - 我的简单代码出了什么问题?

ios - xcode 7.3.1升级后如何防止UILabel被截断