0
votes

I am using attributed string in UITextView. Sample playground can be found here

This is a quick summary of what is happening.

UITextView has padding issue which can be solved using this thanks to @Fattie

I set attributed string in UITextView.

then I calculate textView's height using sizeThatFits method which I am guessing is giving me correct height.

But when I run it, text is trimmed at top, and some space is left at the bottom. Please run the sample playground from here

I guess this might be the reason why textView comes with a default padding but I am not completely sure of it.

Strange thing is, I tried the same with UILabel and it seems to be working perfectly fine with the same settings. You can try the same in the above playground after uncommenting the UILabel.

Can anyone tell me why is this issue happening with UITextView?

1

1 Answers

0
votes

Solved after using

let htmlText = text.data(using: .utf8, allowLossyConversion: false)!
let mutableText = try! NSAttributedString(
        data: htmlText,
        options: [.documentType: NSAttributedString.DocumentType.html],
        documentAttributes: nil)