我正在使用swift在UITextView中呈现一个超文本标记语言视图。下面是代码。
guard let attributedString = try? NSAttributedString(data: htmlContent.data(using: String.Encoding.utf8)!, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil) else {
return
}
textView.attributedText = attributedString
现在我想将文本的颜色设置为白色。该怎么做呢?
发布于 2018-06-17 22:27:37
只需使用textView的textColor
属性:
// ...
textView.attributedText = attributedString
textView.textColor = .white
您也可以在属性字符串本身上设置foregroundColor
-因此,您必须切换到NSMutableAttributedString
:
// ...
attributedString.addAttribute(.foregroundColor, value: UIColor.white, range: NSRange(location: 0, length: attributedString.length))
textView.attributedText = attributedString
https://stackoverflow.com/questions/50897473
复制相似问题