【发布时间】:2022-01-03 12:54:28
【问题描述】:
我有分配给属性文本的 UITextview,它正在正确呈现,但它没有应用链接颜色,在下面 sn-p 链接颜色是 #EB0A1E 但在 textview 它显示为蓝色(默认链接颜色)
textView.attributedText = "Google.com link <a href = \"https://google.com\" style=color:#EB0A1E;>here</a><br><br> Hello there".htmlToAttributedString
extension String {
var htmlToAttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else { return NSAttributedString() }
do {
return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
return NSAttributedString()
}
}
}
【问题讨论】:
标签: ios swift uitextview