Automatically Adjust UIView's Height to It's Subview using AutoLayout (Storyboard)

邮差的信 提交于 2019-12-11 10:11:02

问题


I am using StoryBoards and Autolayout.

Below is the hierarchy:

- Superview
-- UIView (ContentView)
--- UITextField
--- UITextField
--- UITextField
--- UITextField

The UIView(ContentView)'s is constrained to Left, Top, Right of the SuperView with the offset of 20;

The Bottom of UIView(ContentView) is not constrained to anything.

I would like the contentView's height adjusted based on how many textField in it. Any thoughts how I could achieve this using AutoLayout?

I am very new in Autolayout. Used to do all UI in code.

Any thoughts?

Thank you!!


回答1:


Silly me, found the answer, I simply restrict the height of all the subviews and then constraint the most bottom of the bottom subview to the UIView/ContentView



来源:https://stackoverflow.com/questions/30408625/automatically-adjust-uiviews-height-to-its-subview-using-autolayout-storyboar

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