htmlテキストを表示するためにASTextNode(AsyncDisplayKitのUILabelと同じ)を表示しようとしています。ラベルの属性付きテキストを設定するだけです。NSAttributedString htmlリンクの色を変更します。
私は私の文字列をどのように働くかある:
この拡張機能を使用して、私はNSAttributedStringにHTMLテキストを変換:
extension String {
var html2AttributedString: NSAttributedString? {
guard let data = data(using: .utf8) else { return nil }
do {
return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch let error as NSError {
print(error.localizedDescription)
return nil
}
}
var html2String: String {
return html2AttributedString?.string ?? ""
}
}
それから私は私のラベルの詳細を設定します。
self.displayContent = NSMutableAttributedString(attributedString: content.html2AttributedString!)
self.displayContent?.addAttribute(NSFontAttributeName, value: UIFont.fontMainFeedContentFont(), range: NSRange.init(location: 0, length: self.displayContent!.length))
ので、私は自分のフォントで自分のラベルを持っています。問題は私のラベルのリンクの色を変えることができないということです。私はそれがシステムの青です。
どのようにリンクの色を変更できますか?
ありがとうございました。
、あなたを行います下線の色を意味しますか? – KrishnaCA
いいえ、テキストの色は黒、リンクの色は青です – user2206906