我想增加 html attributed string
的字体尺寸。我也跟着this question但仍然无法正常工作。我使用下面的代码将html string
更改为attributed string
。
let strmy = model.strItineraryDescription.html2AttributedString
lblDescription.attributedText = strmy
extension String {
var html2AttributedString: NSAttributedString? {
do {
return try NSAttributedString(data: Data(utf8), options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue,NSFontAttributeName : UIFont.systemFont(ofSize: 20.0, weight: UIFontWeightSemibold)], documentAttributes:nil)
} catch {
print(error)
return nil
}
}
var html2String: String {
return html2AttributedString?.string ?? ""
}
}
我的html
字符串如下所示: -
<strong><u>Featured Program</u></strong></p>
\n<ol>
\n <li>Arrival at Delhi airport. You will receive by our representative.</li>
\n <li>Driving to Agra and exploring the city.</li>
\n <li>Back to Hotel for Overnight stay.</li>
\n</ol>
\n<p><strong>City Features</strong></p>
\n<ol>
\n <li><strong>Visit to Agra Fort \U2013 </strong>Former Name Badalgarh, Shah-Jahan spent his last eight years here. You can watch the mesmerizing view of Taj Mahal from this fort just like Shah Jahan.</li>
\n <li><strong>Visit to Taj Mahal \U2013</strong> It took 21 years to build and stood in 1653. The palace is considered as the symbol of love. Shah Jahan built this wonder in the memory of his wife Mumtaj Mahal.</li>
\n</ol>
\n<p><strong>(Both Agra Fort and Taj Mahal are UNESCO Declared world heritage site)</strong>