UIStackView 是否可以滚动? [英] Is it possible for UIStackView to scroll?
本文介绍了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.
您可以从 github 获取.
基本上,重新创建示例(用于垂直滚动):
Basically, to recreate the example (for vertical scrolling):
- 创建一个
UIScrollView
,并设置其约束. - 添加一个
UIStackView
到UIScrollView
- 设置约束条件:
Leading
、Trailing
、Top
&Bottom
应该等于UIScrollView
- 在
UIStackView
和UIScrollView
之间设置一个相等的Width
约束. - 在
UIStackView
上设置 Axis = Vertical、Alignment = Fill、Distribution = Equal Spacing 和 Spacing = 0 - 向
UIStackView
添加多个 - 运行
UIViews
- 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 theUIStackView
andUIScrollView
. - Set Axis = Vertical, Alignment = Fill, Distribution = Equal Spacing, and Spacing = 0 on the
UIStackView
- Add a number of
UIViews
to theUIStackView
- Run
将第4步中的Width
换成Height
,并在第5步中设置Axis
= Horizontal
,得到一个水平的 UIStackView.
Exchange Width
for Height
in step 4, and set Axis
= Horizontal
in step 5, to get a horizontal UIStackView.
这篇关于UIStackView 是否可以滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文