我想显示带有可单击链接的警报对话框的消息。
例如,我的消息For more info please visit our website: (I WANT TO PUT LINK HERE FOR USER TO INTERACT)

我如何实现这种目标?

这是我的代码

let dialog = MDCAlertController(title: DialogErrorMessage().errorTitle, message: message)

    dialog.buttonTitleColor = UIColor(red:0.03, green:0.62, blue:0.09, alpha:1.0)

    let okayButton = MDCAlertAction(title: DialogTitleMessage().okayTitle) { (action) in

    }
    dialog.addAction(okayButton)

    dialogPresent(view: dialog)

最佳答案

要使您的自定义MDCAlertController中的标签可点击,您需要执行以下解决方法:

  • 枚举警报控制器中的标签。 (alertController是您的MDCAlertController实例的名称)
    for (UILabel *label in [alertController.view subviewsOfClass:[UILabel class]]) { //Here you get the **label instance**}
  • 在标签上添加点击手势为
    let tap = UITapGestureRecognizer(target: self, action: Selector("tapFunction:")) label.addGestureRecognizer(tap)
  • 将标签的用户交互设置为true
    label.isUserInteractionEnabled = true

  • 完整的代码如下:
    for (UILabel *label in [alertController.view subviewsOfClass:[UILabel class]]) {
            label.isUserInteractionEnabled = true
            let tap = UITapGestureRecognizer(target: self, action: Selector("tapFunction:"))
            label.addGestureRecognizer(tap)
        }
    

    关于ios - 如何在MDCAlertController的消息中添加可点击的链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54634028/

    10-09 22:36