具有自动布局的UIView不会增加UIScrollView内的高度 [英] UIView with Auto Layout doesn't increase height inside UIScrollView
问题描述
我想做的是有一个类似于以下线框的页面,所有UILabel
的高度都应根据文本动态变化:
What I'm trying to do is have a page similar to following wireframe that all UILabel
s height should dynamically change based on the text:
我目前在UIScrollView
中有一个UIView
.问题是我无法根据其内容正确调整UIView
的大小,例如,当描述很长时.可以从此处
I currently have a UIView
inside a UIScrollView
. The issue is I can't get the UIView
resize properly based on the its content, for example when description is long. The sample code can be downloaded from here
如果不喜欢编写代码,请遵循以下约束及其设置方式:
If not into the mood for code, here's the constraints and how it's setup:
我尝试使用这篇文章
推荐答案
最终,找到了解决方案.需要删除UIScrollView
和contentView
的任何高度限制,并添加一个底部限制,如下所示:
FINALLY, found the solution to it. Needed to remove any height constraint for UIScrollView
and contentView
and add a bottom constraint as shown below:
使用此更改更新了示例应用程序.现在,示例应用程序可以按预期运行.
Updated the sample app with this change. Now the sample app works as expected.
这篇关于具有自动布局的UIView不会增加UIScrollView内的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!