2 Replies
      Latest reply on Oct 3, 2019 12:30 PM by awebb
      Mellberg Level 1 Level 1 (0 points)

        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 <i>, <b>, and <center>.

         

        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 <b>.

         

        Here's the code:

            func htmlAttributedString(fontSize: CGFloat = 17.0) -> NSAttributedString? {
                let fontName = UIFont.systemFont(ofSize: fontSize).fontName
                let string = self.appending(String(format: "<style>body{font-family: '%@'; font-size:%fpx;}</style>", 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