【发布时间】:2020-10-12 19:21:56
【问题描述】:
如何在swift中更改NSAttributedString的字体大小和字体颜色?
@IBOutlet weak var detailsTextView: UITextView!
if let data = htmltext.data(using: String.Encoding.utf8, allowLossyConversion: true)
{
do
{
let newFont = UIFont(name: "Georgia", size: 22.0) ?? UIFont()
let attributedText = try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
detailsTextView.attributedText = attributedText
}
catch{}
}
htmltext是需要设置为UILabel的html值
【问题讨论】:
-
yourlabel.attributetext = 属性文本在哪里
-
@Anbu.Karthik 我这里没有提到。
-
@PrabuRaj 你可以试试下面的代码 swift 3.0
-
@Anbu.Karthik 你对此有什么答案吗?因为没有一个答案能给我预期的结果..
-
@PrabuRaj 你能添加你的 html 字符串的样子吗?
标签: ios swift nsattributedstring