gpt4 book ai didi

swift - 使用 tableView 单元格中的自动布局实现 TextView 的自动高度

转载 作者:行者123 更新时间:2023-11-30 10:44:55 25 4
gpt4 key购买 nike

我想根据表格 View 单元格中的内容设置 TextView 的高度。

enter image description here

我将 TextView 的顶部固定到职位名称 UILabel,将底部固定到内容 View (父级),但它不起作用。有这种布局定位的教程吗?

如何添加约束来解决自动高度问题?

当前的限制 enter image description here

最佳答案

正如我所见,您在单元格中还有一些其他设置。支持动态高度

  1. 您可以为 UITextView 提供固定高度约束。
  2. 摆脱这种限制。
  3. 在从 cellForRowAt 方法返回单元格之前更新它。

所以,你的 cellForRowAt 方法最终会像这样

tableCell.textViewHeightConstraint = textView.contentSize.height
tableCell.setNeedsUpdateConstraints()
tableCell.setNeedsLayout()
return tableCell

关于swift - 使用 tableView 单元格中的自动布局实现 TextView 的自动高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55936509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com