0
我使用文本視圖。我想刪除,如果一個網址是在文本視圖內輸入的。我找不到網址present.can無法做到這一點。任何人請幫助當在url中輸入url時,移除在UItextview中找到的url鏈接3
我使用文本視圖。我想刪除,如果一個網址是在文本視圖內輸入的。我找不到網址present.can無法做到這一點。任何人請幫助當在url中輸入url時,移除在UItextview中找到的url鏈接3
試試這個,我認爲這會幫助你。
let texty : String = "http://www.google.com. I am vaishanvi, Competed Bachelor degree (Information technology). My blog url is http://iosdevcenters.blogspot.in, Check It"
let types: NSTextCheckingResult.CheckingType = .link
var URLStrings = [NSURL]()
let detector = try? NSDataDetector(types: types.rawValue)
let matches = detector!.matches(in: texty, options: .reportCompletion, range: NSMakeRange(0, texty.characters.count))
textView.text = texty
for match in matches {
URLStrings.append(match.url! as NSURL)
let path:String = match.url!.absoluteString
textView.text = textView.text.replacingOccurrences(of: path, with:"")
}
print(textView.text)
print(URLStrings)
謝謝你的工作 – farzeen
請問您能詳細解釋一下嗎? –
public func textView(_ textView:UITextView,shouldChangeTextIn範圍:NSRange,replacementText text:String) - > Bool 委託方法你必須檢查TextView的子字符串文本是URL你必須刪除子字符串並將文本應用到UITextView。 –