How to remove the extra white space?

Hi,


My Code Snippet

myTextView.heightAnchor.constraint(greaterThanOrEqualToConstant: 20).isActive = true
let myHTMLString =" some html text"

myTextView.attributedText = myHTMLString.htmlToAttributedString


extension String {
    var htmlToAttributedString: NSAttributedString? {
        guard let data = data(using: .utf8) else { return NSAttributedString() }
        do {
            return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue], documentAttributes: nil)
        } catch {
            return NSAttributedString()
        }
    }
    var htmlToString: String {
        return htmlToAttributedString?.string ?? ""
    }
}


HTMLString converted to attributed string.

But,

extra lines of white spaces exists in myTextView at the bottom.

What is the reason?

How to recitify it?


Thanks In Advance

Answered by Claude31 in 408127022

Have you checked there is no line feed at the end of HTML string ?

Accepted Answer

Have you checked there is no line feed at the end of HTML string ?

Is it the exact code ? I’m surprised you don’t get an error at line let myHTMLString =" some html text"

Hi,

That is not the exact text..

There is line feed at the end of attributed String.

i got solution by removing it.


Thanks a lot Claude31

How to remove the extra white space?
 
 
Q