I have a UITextView where content is aligned by NSTextAlignmentJustified. In the cellForRowAtIndexPath: add this text view to cell content view and change frame according it’s content by
UITextView *commentsTextView = (UITextView *)[self getCommentField:comment];
[cell.contentView addSubview:commentsTextView];
CGRect tempFrame = commentsTextView.frame;
tempFrame.size.height = commentsTextView.contentSize.height;
commentsTextView.frame = tempFrame;
So far, so good. Now, how to detect contentSize of that view for heightForRowAtIndexPath:?
I tried
NSString *comment = [[self.allComments objectAtIndex:indexPath.row] objectForKey:@"commentText"];
CGSize constraintSize = CGSizeMake(315.0f, MAXFLOAT);
CGSize size = [comment sizeWithFont:[UIFont systemFontOfSize:14.0]
constrainedToSize:constraintSize
lineBreakMode:NSTextAlignmentJustified];
Also I tried lineBreakMode:NSLineBreakByWordWrapping and so. But cell height is always smaller when text is long, because there seems to be no way how to coumpute size of justified text (because of the white spaces in the middle of text). Font is same.
OK, i got it. UITextView has 8 pixels insect from each side, co my CGSizeMake(315.0f, MAXFLOAT); have to be CGSizeMake(299.0f, MAXFLOAT);