[英]How do I make a stack view or container view wrap contents?
rookie IOS developer here migrating from an Android code base. 新手IOS开发人员在这里从Android代码库迁移。
In android if we wanted a container that automatically adjusted its height based on its internal contents, we would just do something like the following 在android中,如果我们想要一个根据内部内容自动调整高度的容器,我们只需执行以下操作
<LinearLayout
android:orientation="vertical"
android:layout_width="500dp"
android:layout_height="wrap_content">
...
</LinearLayout>
How is this achieved in autolayout through the storyboard? 如何通过故事板在自动布局中实现这一目标? How can I make a
stackview
or containerview
's width or height to be wrap_content
? 如何使
stackview
或containerview
的宽度或高度成为wrap_content
?
You can accomplish the same on ios by using UIStackView (Verticl/Horizontal) or UIScrollview 您可以使用UIStackView(Verticl / Horizontal)或UIScrollview在ios上完成相同的操作
let me explain the whole process in scrollview 让我在scrollview中解释整个过程
1- drag a scrollview to your view controller in storyboard file/Xib 1-将scrollview拖动到storyboard文件/ Xib中的视图控制器
2- give the storyboard leading , trailing , top , bottom constraints to the main view 2-给出主视图的故事板前导,尾随,顶部,底部约束
3- drag a UIView (contentView) inside the scrollView and hook it's leading , trailing , top , bottom constraints to the scrollview 3-在scrollView中拖动UIView(contentView)并将其前导,尾随,顶部,底部约束挂钩到scrollview
4- control-drag from the contentView to the mainView and select Equal-widths constraint 4-控制 - 从contentView拖动到mainView并选择Equal-widths约束
until this step you have a scrollview that is ready to be wrapped according to the inner size of it's components 直到这一步,你有一个滚动视图,可以根据它的组件的内部大小进行包装
5- drag a UILabel and hook it's leading , trailing , top , bottom constraints to the contentView 5-拖动UILabel并将其前导,尾随,顶部,底部约束挂钩到contentView
in runtime change the content of that label and the scrollview will wrap according to the label content 在运行时更改该标签的内容,并且scrollview将根据标签内容进行换行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.