Hello I have the next code:
NSMutableAttributedString *mutableText = [[NSMutableAttributedString alloc] initWithData:[Texto dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
documentAttributes:nil
error:nil];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.lineBreakMode = NSLineBreakByTruncatingTail;
[mutableText addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, mutableText.length)];
self.Texto.attributedText = mutableText;
[self.Texto setNeedsLayout];
[self.Texto layoutIfNeeded];
CGRect rect = [self.Texto.attributedText boundingRectWithSize:CGSizeMake(self.Texto.frame.size.width , NSUIntegerMax)
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
context:nil];
NSLog(@"%@ %@",NSStringFromCGRect(self.Texto.bounds),NSStringFromCGRect(rect));
This code is not working when I add the attribute NSMutableParagraphStyle to the NSMutableAttributedString. I´m getting 35 pixel for Height when I should get a 705 pixels for my text. I get the right value (704.8897) If I remove the next line:
[mutableText addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, mutableText.length)];
I´m lost, do you know where I´m wrong?