I have text that contains HTML formatting that I am trying to display in a view. I am currently using NSAtributedString to display text inside a UILabel .
I get the assigned string as follows:
NSString *htmlString = @"<html>" " <head>" " <style type='text/css'>" " body { font: 12pt 'Helvetica'; color: #111111; }" " </style>" " </head>" " <body>"; htmlString = [htmlString stringByAppendingString:self.descriptionText]; htmlString = [htmlString stringByAppendingString:@"</body></html>"]; NSError *err = nil; NSAttributedString *attributedText = [[NSAttributedString alloc] initWithData: [htmlString dataUsingEncoding:NSUTF8StringEncoding] options: @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes: nil error: &err];
and then assign it to the label attributedText property. The self.descriptionText property is an NSString that can contain simple HTML markup, such as p tags or span tags with inline styles. The wrapping technique in an HTML document was found in another StackOverflow article.
UILabel set to Lines = 0 and Line Breaks = Word Wrap. The behavior I see is that the label grows properly to fit the entire line, but the last line of the line is never displayed, no matter how long the line lasts.
Here is a screenshot with two shortcuts. The top label (with a yellow background) has my HTML bound string. You can see that the label is sized to allow 3 lines of text, but only two are displayed, and the rest are truncated. The second label (with a red background) had a simple string assigned to its Text property, and it draws fine.
The HTML string used in the example image contains the following text:
<p>With the world&

A valid answer explains how I can prevent the truncation of the last line or provide a simple alternative method for displaying HTML text in a view. Thanks.
html ios objective-c uilabel nsattributedstring
Andrew H
source share