I am using attributedText property of label to render html.
It is working fine with rendering bold and italic. However when i try to render html line breaks it just cuts off all the text appearing after the line break.
NSString* view = @"<i>Testing</i> and this is <b>bold</b> <br> This should be in next line";
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *preview = [[NSAttributedString alloc] initWithData:[view dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:nil];
self.labelView.attributedText = preview;
Help is required
As mentioned in the comments, for me this issue was not with HTML rendering but with forgetting to set "Number of Lines" to 0 on the UILabel.
I tried and this worked
NSString* view = @"<i>Testing</i> and this is <b>bold</b> <br> This should be in next line";
NSAttributedString *preview =[[NSAttributedString alloc] initWithData:[view dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
documentAttributes:nil error:nil];
UILabel *lbl = [[UILabel alloc] initWithFrame:cell.textLabel.frame];
[lbl setAttributedText:preview];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With