UITableViewCell自適應高度

1.常見問題,

a.UILabel的高度自適應,

b.TableViewCell高度的自適應。

2.解決方案:UILabel高度的自適應, 首先是設定好label的約束。

UILabel屬性設置:


主要代碼包括2段:2個缺一不可

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 170;
    
}




發佈了59 篇原創文章 · 獲贊 2 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章