【发布时间】:2012-12-07 05:21:30
【问题描述】:
我有一个 UITextView,其中内容由 NSTextAlignmentJustified 对齐。在 cellForRowAtIndexPath: 中将此文本视图添加到单元格内容视图并根据其内容更改框架
UITextView *commentsTextView = (UITextView *)[self getCommentField:comment];
[cell.contentView addSubview:commentsTextView];
CGRect tempFrame = commentsTextView.frame;
tempFrame.size.height = commentsTextView.contentSize.height;
commentsTextView.frame = tempFrame;
到目前为止,一切都很好。现在,如何为 heightForRowAtIndexPath: 检测该视图的 contentSize? 我试过了
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];
我也试过 lineBreakMode:NSLineBreakByWordWrapping 等等。但是当文本很长时,单元格高度总是更小,因为似乎没有办法计算 justified 文本的大小(因为文本中间有空格)。字体相同。
【问题讨论】:
标签: ios cocoa-touch uitableview ios6 uitextview