2017-07-14 59 views
0

我使用文本视图。我想删除,如果一个网址是在文本视图内输入的。我找不到网址present.can无法做到这一点。任何人请帮助当在url中输入url时,移除在UItextview中找到的url链接3

+0

请问您能详细解释一下吗? –

+0

public func textView(_ textView:UITextView,shouldChangeTextIn范围:NSRange,replacementText text:String) - > Bool 委托方法你必须检查TextView的子字符串文本是URL你必须删除子字符串并将文本应用到UITextView。 –

回答

0

试试这个,我认为这会帮助你。

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) 
+0

谢谢你的工作 – farzeen