我有一个UITableView
并在单元格内有我自己的自定义单元格,其中包含UILabel
。TableView单元格大小与标签大小有关
我想根据标签中的文字增加tableView的行大小。 我使用的AutoLayout和我的标签有20填充左侧和8填充右,顶部和底部。
我被困在这里,因为标签上下文有时候很小,有时非常大,我想增加文本增加时该行的大小。
我有一个UITableView
并在单元格内有我自己的自定义单元格,其中包含UILabel
。TableView单元格大小与标签大小有关
我想根据标签中的文字增加tableView的行大小。 我使用的AutoLayout和我的标签有20填充左侧和8填充右,顶部和底部。
我被困在这里,因为标签上下文有时候很小,有时非常大,我想增加文本增加时该行的大小。
设置UILabel.numberOfLines
为0,并添加到您的UITableViewDelegate
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
谢谢你,先生.. !!它的工作原理就是我想要的。 :)) –
根据[文档](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.html),这并不完全正确:首先,您可以在表格视图中设置这些值,而不是从这些方法中返回它们。其次,您应该使用'estimatedRowHeight'值的实际大小,并且仅对实际的'rowHeight'使用'UITableViewAutomaticDimension'。 –
分享一些代码可以帮助 – ppaulojr
你想在我看来,文本字体大小,但该行高度的变化,其可能的,但不是很好'UI' – meda