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
,并设置其约束. - 在
UIScrollView
中添加一个 - 设置约束:
Leading
、Trailing
、Top
&Bottom
应该等于UIScrollView
中的那些 - 在
UIStackView
和UIScrollView
之间设置相等的Width
约束. - 在
UIStackView
上设置Axis = Vertical,Alignment = Fill,Distribution = Equal Spacing,Spacing = 0 - 在
UIStackView
中添加多个 - 运行
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 可以滚动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIStackView 可以滚动吗?


基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01