[英]UIStackView inside UIScrollView: how to center-align stack view / items?
I have a UIStackView
inside a UIScrollView
, and when the width of all items in stack view is less then the width of the scroll view, I want to make the stack view (or the items) to be horizontally centered aligned with the scroll view. 我在
UIScrollView
有一个UIStackView
,当堆栈视图中所有项目的宽度小于滚动视图的宽度时,我想使堆栈视图(或项目)与滚动视图水平居中对齐。
I have the following constraints: 我有以下约束:
For scrollView: H:|[stackView]|
对于scrollView:
H:|[stackView]|
and V:|[stackView]|
和
V:|[stackView]|
(so stack view fits with scroll view) (所以堆栈视图适合滚动视图)
But I can see the stack view seems to shrink to a minimum size that just enough for all its arranged subviews' intrinsic content size, and it's left aligned to the scroll view. 但我可以看到堆栈视图似乎缩小到最小尺寸,足以满足所有排列的子视图的内在内容大小,并且它与滚动视图保持对齐。
Is there anyway to make it horizontally-centred in the scroll view? 反正是否在滚动视图中使其水平居中?
Thanks! 谢谢!
看看这个: https : //developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/LayoutUsingStackViews.html搜索'Dynamic Stack View',它对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.