我正在尝试将表格中的一行调整为 textView 的高度,以便用户不必滚动 textView,而是滚动表格。到目前为止,我所实施的似乎大部分时间都有效,尽管有时行高有点太小,迫使用户稍微滚动文本视图,或者行高太大,在文本结束后创建大量空白. 我怎样才能恰到好处地构图?
代码:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Set the textview frame
CGRect frame = self.contentTextView.frame;
frame.size.height = [self.summary boundingRectWithSize:CGSizeMake(280, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:self.contentTextView.font} context:nil].size.height + 60;
self.contentTextView.frame = frame;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return the height for the rows
if (indexPath.section == 0) {
return 60;
}
if (indexPath.section == 3) {
// Size content row based on text
return [self.summary boundingRectWithSize:CGSizeMake(280, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:self.contentTextView.font} context:nil].size.height + 100;
}
return 44;
}