Donner à UITextView un lien URL cliquable

Salut j'ai été sur ce problème pendant un moment maintenant, j'ai lu quelques messages déjà un je ne peux pas comprendre comment faire un UITextView cliquable qui envoie sur Internet. Voici mon code:

 func transformText(text: Ssortingng, underlined: Bool, linkURL: Ssortingng) -> NSAtsortingbutedSsortingng { let textRange = NSMakeRange(0, text.characters.count) let atsortingbutedText = NSMutableAtsortingbutedSsortingng(ssortingng: text) if underlined{ atsortingbutedText.addAtsortingbute(NSUnderlineStyleAtsortingbuteName , value: NSUnderlineStyle.styleSingle.rawValue, range: textRange) atsortingbutedText.addAtsortingbute(NSUnderlineColorAtsortingbuteName , value: UIColor.lightGray, range: textRange) } atsortingbutedText.addAtsortingbute(NSFontAtsortingbuteName , value: UIFont(name: "Helvetica-Light", size: 17)!, range: textRange) atsortingbutedText.addAtsortingbute(NSForegroundColorAtsortingbuteName , value: UIColor.lightGray, range: textRange) if(linkURL != "") { let atsortingb = [NSLinkAtsortingbuteName: NSURL(ssortingng: linkURL)!] atsortingbutedText.addAtsortingbutes(atsortingb, range: textRange) } return atsortingbutedText } 

Voici comment je l'appelle:

 TextContent.atsortingbutedText = transformText(text: self.TelBox.TextContent.text, underlined: true, linkURL: "https://www.google.fr")` 

Merci d'avance

Sélectionnez l'UITextView sur le storyboard et allez dans 'Afficher l'inspecteur des attributes', puis dans 'comportement' désélectionne 'Editable' et dans 'Data Detector' select 'Link'. Ensuite, allez dans 'Sohw the Identity inspector' et dans 'traits' select 'Link' et 'Selected'.

Le fait est que vous voulez que UITextView rende cliquable vous oblige à rendre UITextView non modifiable parce que lorsque vous click le text, le keyboard va démarrer. Pour éviter cela, vous pouvez utiliser

textView.isEditable = false

J'espère que cela aide.

Assurez-vous que vous avez également activé la détection du type de données. Pour les hyperliens:

 theTextView.dataDetectorTypes = [.link]