1

コンテンツがNSTextAlignmentJustifiedによって整列されるUITextViewがあります。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なども試しました。ただし、テキストが長い場合、セルの高さは常に低くなります。これは、位置揃えされたテキストのサイズを計算する方法がないように思われるためです(テキストの中央に空白があるため)。フォントは同じです。

4

1 に答える 1

1

はい、分かりました。UITextViewには、両側から8ピクセルの昆虫があります。私のCGSizeMake(315.0f、MAXFLOAT); CGSizeMake(299.0f、MAXFLOAT)である必要があります。

于 2012-12-19T19:20:07.320 に答える