我有一个自定义表格视图单元格,我想根据标签中的文本量自动调整大小。自动调整大小自定义UITableViewCell
在我的表视图控制器我用UITableViewAutomaticDimension
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 0 {
if indexPath.row == 0 {
return 200
} else {
return 49
}
} else if indexPath.section == 1 {
return 100
} else if indexPath.section == 2 {
if indexPath.row == 0 {
return 200
} else {
return 400
}
} else {
return UITableViewAutomaticDimension
}
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
这是我结束了。
确保将contentView的尾部,前导,顶部和底部连接到其子视图。 – genaks
你看过这篇文章吗? http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights – Dominic
做一些像[链接](http:// useyourloaf。 com/blog/table-view-cells-with-varying-row-heights /),它会帮助你 –