Mad*_*ala 1 xcode uitextview swift5
我有带电话号码的 UITextView。在 ios Swift 5 中单击 UITextView 中的电话号码时如何拨打电话。
TextView 提供一种委托方法来获取任何检测器的点击事件,如电话号码、链接。
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if URL.scheme == "tel" {
let phone = URL.absoluteString.replacingOccurrences(of: "tel:", with: "")
if let callUrl = URL(string: "tel://\(phone)"), UIApplication.shared.canOpenURL(callUrl) {
UIApplication.shared.open(callUrl)
}
}
return true
}
Run Code Online (Sandbox Code Playgroud)
也不要忘记这一点。
textView.dataDetectorTypes = [.phoneNumber]
textView.delegate = self
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
995 次 |
| 最近记录: |