gpt4 book ai didi

swift - 使用自动布局设置 UIView 高度以适合 UILabel subview

转载 作者:行者123 更新时间:2023-11-30 13:15:08 25 4
gpt4 key购买 nike

我尝试做什么

我有自定义 UIView,其中包含 UILabel 作为 subview 。我希望 UIView 包裹 UILabel 高度并根据文本长度设置其高度。将文本添加到 label.text 时,UILabel 会正确调整其高度。到目前为止一切顺利。

问题

UIView 不通过 UILabel 内容调整高度。文本应该位于下面的白色 UIView 内。这应该可以通过约束来解决,对吗?但我还是做不到。这可以纯粹通过 Storyboard来完成还是我必须在代码中手动设置 UIView 高度?

enter image description here

结果: enter image description here

最佳答案

尝试在 Interface Builder 中将 UILabel super View 的 Content Hugging 属性设置为 1000:

enter image description here

关于swift - 使用自动布局设置 UIView 高度以适合 UILabel subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38304855/

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