本文介绍了UIStackView可以滚动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在UIStackView中添加了更多可以显示的视图,如何使 UIStackView
滚动?
Let's say I have added more views in UIStackView which can be displayed, how I can make the UIStackView
scroll?
推荐答案
如果有人正在寻找无代码的解决方案,我创建了一个示例,使用自动布局在故事板中完全执行此操作。
In case anyone is looking for a solution without code, I created an example to do this completely in the storyboard, using Auto Layout.
您可以从获取。
基本上,要重新创建示例:
Basically, to recreate the example:
- 创建
UIScrollView
,并设置其约束。 - 将
UIStackView
添加到UIScrollView
- 设置约束:
前导
,追踪
,热门
&底部
应该等于UIScrollView
- 设置相等UIStackView和
UIScrollView
之间的宽度
约束。 - 在UIStackView上设置Axis = Vertical,Alignment = Fill,Distribution = Equal Spacing和Spacing = 0
- 添加一些
UIViews
到UIStackView
- 运行
- Create a
UIScrollView
, and set its constraints. - Add a
UIStackView
to theUIScrollView
- Set the constraints:
Leading
,Trailing
,Top
&Bottom
should be equal to the ones fromUIScrollView
- Set up an equal
Width
constraint between the UIStackView andUIScrollView
. - Set Axis = Vertical, Alignment = Fill, Distribution = Equal Spacing, and Spacing = 0 on the UIStackView
- Add a number of
UIViews
to theUIStackView
- Run
这篇关于UIStackView可以滚动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!