简体   繁体   English

当在 swift 中键入 url 时,删除在 UItextview 中找到的 url 链接 5

[英]Remove url link found in UItextview when a url is typed in swift 5

I am using a text view.我正在使用文本视图。 I want remove if a url is typed inside the text view.I am not able to do that after finding the url present如果在文本视图中键入 url,我想删除。在找到 url 后,我无法执行此操作

Try the following:尝试以下操作:

yourTextView.dataDetectorTypes = []
    func removingUrls() -> String {
        guard let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) else {
            return self
        }
        return detector.stringByReplacingMatches(in: self,
                                                 options: [],
                                                 range: NSRange(location: 0, length: self.utf16.count),
                                                 withTemplate: "")
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM