ios 在堆栈视图中设置某些项目之间的空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34575732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:30:37  来源:igfitidea点击:

Setting space between some items in stack view

iosxcode

提问by Nahouto

In Interface Builder, I use a horizontal UIStackView and want to place the items as this :

在界面生成器中,我使用水平 UIStackView 并希望将项目放置为:

   xx   xx   xx

every x symbolize an item. Item1 and item2 should be stuck one to the other, but item2 and item3 should be spaced and so on. That means I do not want constant spacing between all the items.

每个 x 代表一个项目。项目 1 和项目 2 应该相互粘在一起,但项目 2 和项目 3 应该间隔开,依此类推。这意味着我不希望所有项目之间保持恒定的间距。

How can I do so ?
(maybe an equivalent of flexible space of toolbars)

我怎么能这样做?
(可能相当于工具栏的灵活空间)

Thanks !

谢谢 !

采纳答案by Ajay Kumar

Inside your horizontal stack view have three more horizontal stack views so that you can have control over spacing and distribution for each item. See screenshot below:

在您的水平堆栈视图中还有三个水平堆栈视图,以便您可以控制每个项目的间距和分布。请看下面的截图:

enter image description here

在此处输入图片说明

回答by Q Liu

It's an answer based on Lumialxk's reply. Choose the stack view you want to work on, and change the spacing property to your desired value.

这是基于 Lumialxk 回复的答案。选择您想要处理的堆栈视图,并将间距属性更改为您想要的值。

Screen shot of the property panel

属性面板的屏幕截图

回答by Warif Akhand Rishi

iOS 11 and above

iOS 11 及以上

stackView.setCustomSpacing(32.0, after: headerLabel)

For more info: Stack View Custom Spacing

有关更多信息:堆栈视图自定义间距

回答by Tung Fam

Programmatically for each view:

以编程方式为每个视图

stackView.spacing = 10.0

If you want to make a custom spacingafter each view and you need to support lower than iOS11:

如果要在每个视图后自定义间距并且需要支持低于 iOS11

Create a clear UIView with height and add it as an addArrangedSubviewinto the stackView.

创建一个清晰的具有高度的 UIView 并将其添加addArrangedSubview到 stackView 中。

回答by Lumialxk

In a stack view,you can only define the constant space between items.It's easy to do such things,just choose the stack view in the outline and set the value of space.

在stack view中,你只能定义items之间的恒定空间,做这样的事情很容易,只需要在outline中选择stack view,设置space的值即可。

回答by Fox5150

Swift 4 : If you want for example set a space after the first subview :

Swift 4:例如,如果您想在第一个子视图之后设置一个空格:

stackView.setCustomSpacing(30.0, after: stackView.subviews[0])