Word "TM" needs to be font-size 6px.
let newText = "My new trade mark is MELLON<sup style="font-size:6px">TM</sup> Corporation"
What I do, I convert it to AttributedString:
let htmlToNSAttributedString = NSAttributedString(data: self, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
And it goes well: before custom font
(when the font size is 10, it matches default size of NSAtrString)
I have to match this text with design and added customized font to it:
mutable.addAttributes([.font : font], range: NSMakeRange(0, mutable.length))
And get next result: after custom font
So the custom font and its size overrides the style properties of tag.
How do I keep them?
For example, I have this to work with: printed attributed String
Can I retract data for exact parts of NSAttributedStr? So I can store it and then add parts back together?
EDIT
Added some more code for reference
let newText = "My new trade mark is MELLON<sup style=\"font-size:6px\">TM</sup> Corporation"
let data = newText.data(using: .utf8)
let attrString = try? NSMutableAttributedString(
data: data ?? Data(),
options: [
NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html,
NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue,
],
documentAttributes: nil
)
let mainAttributedText = NSMutableAttributedString()
mainAttributedText.append(attrString ?? NSMutableAttributedString())
label.textStorage?.append(mainAttributedText)