我@railwayparade你應該使用
cell.textLabel.numberOfLines = 0;
使用heightForRowAtIndexPath計算單元需要的大小一致認爲是
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// replace "THE_TEXT" with the text you are displaying and "TEXT_LABEL_FONT" with the font you're using in the cell
CGSize size = ["THE_TEXT" sizeWithFont:"TEXT_LABEL_FONT" constrainedToSize:CGSizeMake(self.table.bounds.size.width, HUGE_VALF) lineBreakMode:NSLineBreakByWordWrapping];
return size.height;
}
你可能想繼承的UITableViewCell並重寫layoutSubviews設置爲textLabel到準確的大小,並添加填充,因爲你看到適合
-(void)layoutSubviews // in your UITableViewCell subclass
{
[super layoutSubviews];
self.textLabel.frame = CGRectMake(0.0f,0.0f,self.contentView.bounds.size.width,self.contentView.bounds.size.height);
}
不要忘記,如果在佈局子視圖中添加寬度的填充,則必須更改heightForRowAtIndexPath中的約束寬度。
使用行數爲0的UILabel,UITextView用於顯示和編輯文本。 – railwayparade 2014-10-20 20:42:52
事實上,這將是用戶應該放置他的描述的地方,所以這必須是可編輯的。 – andi 2014-10-20 20:46:04
使用自動佈局,並將文本視圖的頂部和底部固定到單元格的頂部和底部(使用任何所需的填充)。 – rdelmar 2014-10-20 20:52:15