I found the answer and it works correctly for me. I am using NSMutableAttributedString with text and attachments.
I created the NSMutableAttributedString category and add the following method:
- (CGSize)getCoveredSizeForMaxSize:(CGSize)maxSize numberOfLines:(NSInteger)lines { UILabel* dummyLabel = [UILabel new]; [dummyLabel setFrame:CGRectMake(0, 0, maxSize.width, CGFLOAT_MAX)]; dummyLabel.numberOfLines = lines; [dummyLabel setLineBreakMode:NSLineBreakByWordWrapping]; dummyLabel.attributedText = self; [dummyLabel sizeToFit]; return dummyLabel.frame.size; }
Hope this helps someone.
source share