func parseHtmlString(info: String, label: UILabel) {
if let data = info.data(using: .utf8) {
let attributedString = try? NSMutableAttributedString(data: data, options: [.documentType: NSMutableAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
let dynamicFontSize: CGFloat = UIScreen.main.bounds.width/22.0
attributedString?.enumerateAttribute(NSAttributedString.Key.font, in: NSRange(location: 0, length: attributedString?.length ?? 0), options: []) { (value, range, stop) in
if let currentFont = value as? UIFont {
let dynamicSize = currentFont.withSize(dynamicFontSize)
attributedString?.addAttributes([NSAttributedString.Key.font: dynamicSize], range: range)
label.attributedText = attributedString
label.numberOfLines = 0
label.textAlignment = .center
}
}
}
}
I am trying to parse the html string for UILabel here.
At the line, if let currentFont = value as? UIFont, it automatically assigns value = times new roman as UIFont. I want it to be system font.
If I add the line let dynamicSize = UIFont.systemFont(ofSize: 15), the HTML string is not parsing and shows the output as a normal string.
Can anyone please help me? I tried different ways, but no luck.




