我有一個使用自動佈局的UITableView。我有多種類型的單元格,但現在讓我們使用最簡單的單元格,即只有UILabel的單元格。使用自動佈局刪除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。我不想要頂部和底部的填充/邊距紫色。我怎樣才能擺脫它?
看起來你有情節板中的這些設置頁邊距常量。所以它的行爲完全如其。 – sha 2014-10-10 00:39:00
這些邊距是綠色的。他不想在標籤本身內填充。 – Paludis 2014-10-10 06:27:03