我使用有三個標籤標題,日期和說明,從Web的服務,現在我得到的數據,其中一些描述文本太大,說明標籤的框架內調整iOS如何在沒有自動佈局的情況下設置動態tableview單元格高度?
如何與它進行定製的tableview細胞?
我使用有三個標籤標題,日期和說明,從Web的服務,現在我得到的數據,其中一些描述文本太大,說明標籤的框架內調整iOS如何在沒有自動佈局的情況下設置動態tableview單元格高度?
如何與它進行定製的tableview細胞?
寫入viewDidLoad
tableView.estimatedRowHeight = 50
tableView.rowHeight = UITableViewAutomaticDimension
簡單地使用像
目標-C
- (void)viewDidLoad
{
...
...
self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
夫特
override func viewDidLoad() {
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
Objective-C的
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80; // customize the height
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
斯威夫特
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80 // customize the height
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
終於定下您label.numofLines = 0在屬性或程式設計
使用任何一個選擇,肯定工作 –
PLZ您在下面的評論 – Amitkumar
我想知道爲什麼知道你正在尋找一種不使用自動佈局的方法。我相信以前發佈的答案是使用自動佈局
self.tableView.estimatedRowHeight = 50;
self.tableView.rowHeight = UITableViewAutomaticDimension;
的解決方案,你可以設置multiline label根據標籤
的內容沒有自動版式您需要展開分別計算每個單元格的高度(height for each labels +邊距),並返回UITableView數據源方法- tableView:heightForRowAtIndexPath:
中的值。
PLZ檢查我的問題在下面的評論 – Amitkumar