我想显示带有可单击链接的警报对话框的消息。
例如,我的消息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)
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/