J'utilise iOS 11 et Swift 4.Link UITextView ne fonctionne pas à Swift 4
Je suis en train de générer un lien dans programme un UITextView
.
Tous les attributs fonctionnent (c'est-à-dire la couleur, la taille, la plage, etc.) - mais malheureusement, le lien ne fonctionne pas. Quelqu'un peut-il me dire pourquoi?
Voici mon code:
@IBOutlet weak var textView: UITextView!
// Setting the attributes
let linkAttributes = [
NSAttributedStringKey.link: URL(string: "https://www.apple.com")!,
NSAttributedStringKey.font: UIFont(name: "Helvetica", size: 18.0)!,
NSAttributedStringKey.foregroundColor: UIColor.blue
] as [NSAttributedStringKey : Any]
let attributedString = NSMutableAttributedString(string: "Just click here to do stuff...")
// Set the 'click here' substring to be the link
attributedString.setAttributes(linkAttributes, range: NSMakeRange(5, 10))
self.textView.delegate = self
self.textView.attributedText = attributedString
Encore une fois, le lien semble correct, mais en cliquant cela ne fonctionne pas.
Voici la capture d'écran:
Merci! Je regardais trop loin. C'était intéressant de passer de Swift3 à Swift4 cette propriété «éditable» et «sélectionnable» d'une manière ou d'une autre à l'intérieur du story-board (puisque avant cela fonctionnait bien). Mieux vaut le faire par programme - merci! – iKK