I try to solve the issue with the NSAttributedString
and the html in it. I try to draw it in the UILabel
as the attributed text in the UITableViewCell
.
I have a html string:
<span class=\"\">Безвозмездно</span>
So I made an attributed string with the method:
+ (NSAttributedString *)attributedStringWithHTML:(NSString *)HTML {
NSDictionary *options = @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType };
return [[NSAttributedString alloc] initWithData:[HTML dataUsingEncoding:NSUnicodeStringEncoding] options:options documentAttributes:NULL error:NULL];
}
and then I try to calculate the string height in the class method to get the cell height. I use:
if (attrString.length > 0) {
height += truncf([attrString boundingRectWithSize:CGSizeMake(300, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
context:nil].size.height) + 1.0f;
}
So I get the height of the label that is smaller than the label which I get with:
[self.titleLabel sizeToFit];
Can anyone help me with this issue?