当用户点击应用中的任何链接时,如何阻止我的ios应用打开网址?

时间:2019-02-27 06:56:21

标签: ios swift uitextview

当我使用从api获取的数据填充它时,我想阻止我的应用打开可能出现在textview中的网址。

3 个答案:

答案 0 :(得分:1)

未选中“ Link”和“ Address”标志以禁用UItextview中存在的URL,请参见下文。

enter image description here

答案 1 :(得分:0)

您可以使用以下代码:

textView.dataDetectorTypes = []

答案 2 :(得分:0)

如果实现textView(_:shouldInteractWith:in:interaction:)中的UITextViewDelegate,则可以控制是否打开URL。

如果您不希望处理任何URL,只需返回false

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
    return false
}