【发布时间】:2014-10-09 23:27:15
【问题描述】:
我有一个使用自动布局的 UITableView。我有多种类型的单元格,但现在让我们使用最简单的,只有一个 UILabel。
在tableView:heightForRowAtIndexPath:我有以下代码:
[self configureCell:self.detailsCell forRowAtIndexPath:indexPath];
[self.detailsCell layoutIfNeeded];
CGSize size = [self.detailsCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height + 1;
依次调用
- (void)configureCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
cell.detailsLabel.text = self.data.myText;
cell.detailsLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
// [cell.detailsLabel sizeToFit]; <- I tried this, but didn't help
}
我最终得到了这个:
绿色矩形是实际的单元格。紫色矩形是 UILabel。我不想要顶部和底部 紫色 填充/边距。我怎样才能摆脱它?
【问题讨论】:
-
看起来您在情节提要中设置了这些边距的常量。所以它的行为与它应该的完全一样。
-
那些边距是绿色的。他不希望标签本身内有填充。
标签: ios objective-c uitableview interface-builder autolayout