Post

Replies

Boosts

Views

Activity

NSAttributedString conversion: Bold, <b>-tag, not working
I have a String extension function which converts an html string to a NSAttributed string, and it's made up with Swift 3.x. The strings I'm showing in a UILabel consists of different html-tags, like &lt;i&gt;, &lt;b&gt;, and &lt;center&gt;.Using Xcode 9.0.1 and deploying the app with the code onto an iPhone running iOS 10 it's working perfectly.Same app, but deployed to an iPhone running iOS 11, all html-tags are converted - except the &lt;b&gt;.Here's the code: func htmlAttributedString(fontSize: CGFloat = 17.0) -&gt; NSAttributedString? { let fontName = UIFont.systemFont(ofSize: fontSize).fontName let string = self.appending(String(format: "&lt;style&gt;body{font-family: '%@'; font-size:%fpx;}&lt;/style&gt;", fontName, fontSize)) guard let data = string.data(using: String.Encoding.utf16, allowLossyConversion: false) else { return nil } guard let attributedString = try? NSMutableAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) else { return nil } print("\(String(describing: self)):\(#function): attributedString: \(attributedString)") return attributedString }By looking at the attributedString output to the console, I can see that on the iPhone with iOS 10 the attributed string contains .SFUIText, .SFUIText-Italic, and .SFUIText-BoldItalic as it should, but running iOS 11 the .SFUIText-BoldItalic is missing.Have any one else experienced the same issue, and maybe has come up with a solution?//Mellberg
2
0
8.7k
Oct ’17