Here's what my application looks like currently.
你会看到,当字幕文本标签只有一行正确调整大小时,但是当有多行时它会全部混乱。我认为这可能与约束有关?现在我正在使用自动布局约束。您可以在屏幕截图中看到它们。这是创建我的单元格的代码。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> DealCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Deal Cell", forIndexPath: indexPath) as DealCell
let currentBar = bars[indexPath.row] as BarAnnotation
cell.barName.text = currentBar.name
cell.deal.text = currentBar.deal
cell.distanceToBar.text = String(format: "%.3f mi", currentBar.distance)
// Set the height of the table view cells
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 44.0;
return cell
}
有什么想法吗?
答案 0 :(得分:1)
在UITableViewDelegate中使用tableView:heightForRowAtIndexPath:
函数。
使用此功能,您可以单独设置每行的高度。
或者您可以使用本文中的自动布局设置。 http://useyourloaf.com/blog/2014/02/14/table-view-cells-with-varying-row-heights.html