こんにちは私は今この問題を抱えています。私はすでにいくつかの記事を読んでいますが、インターネットで送信できるクリック可能な方法を理解できません。ここに私のコードは次のとおりです。ここでUITextViewにクリック可能なURLリンクを与える
func transformText(text: String, underlined: Bool, linkURL: String) -> NSAttributedString {
let textRange = NSMakeRange(0, text.characters.count)
let attributedText = NSMutableAttributedString(string: text)
if underlined{
attributedText.addAttribute(NSUnderlineStyleAttributeName , value: NSUnderlineStyle.styleSingle.rawValue, range: textRange)
attributedText.addAttribute(NSUnderlineColorAttributeName , value: UIColor.lightGray, range: textRange)
}
attributedText.addAttribute(NSFontAttributeName , value: UIFont(name: "Helvetica-Light", size: 17)!, range: textRange)
attributedText.addAttribute(NSForegroundColorAttributeName , value: UIColor.lightGray, range: textRange)
if(linkURL != "")
{
let attrib = [NSLinkAttributeName: NSURL(string: linkURL)!]
attributedText.addAttributes(attrib, range: textRange)
}
return attributedText
}
は、私はそれを呼び出す方法です:
TextContent.attributedText = transformText(text: self.TelBox.TextContent.text, underlined: true, linkURL: "https://www.google.fr")`
事前
なぜUITextFieldですか?それは編集のためのもので、選択するものではありません。 – Larme
UITextViewをごめんなさい申し訳ありません。 – BigBurger
https://developer.apple.com/documentation/uikit/uitextviewdelegate/1649337-textview?language=swiftデリゲートを設定し、実装して、ドキュメントを読んでください。あなたのtextViewのプロパティをいくつかの値に設定します。 – Larme