How to resize a parent view based on the size of subviews layouted with Autolayout

烂漫一生 提交于 2019-11-28 17:17:43

I've done this with the following setup:

  • the container view has no height constraint
  • the top subview has a spacing constraint from the top of the container view
  • the contained views all have spacing constraints between them
  • the bottom view has a spacing constraint to the bottom of the container view

The auto layout system satisfies these constraints by resizing the container to fit its contents.

Of course, you need to dynamically set the constraints as you alter the contents.

If you are use NSStackView then make sure you don't set a constraint for it's height and width and make sure all sides are anchored.

Also make sure that you set the content Hugging property to 1000.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!