Setting space between some items in stack view

后端 未结 6 507
悲&欢浪女
悲&欢浪女 2021-02-04 23:35

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

   xx   xx   xx

every x symbolize an item. Item1 and

相关标签:
6条回答
  • 2021-02-05 00:22

    Programmatically for each view:

    stackView.spacing = 10.0
    

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

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

    0 讨论(0)
  • 2021-02-05 00:26

    iOS 11 and above

    stackView.setCustomSpacing(32.0, after: headerLabel)
    

    For more info: Stack View Custom Spacing

    0 讨论(0)
  • 2021-02-05 00:31

    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.

    0 讨论(0)
  • 2021-02-05 00:33

    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.

    0 讨论(0)
  • 2021-02-05 00:41

    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:

    0 讨论(0)
  • 2021-02-05 00:41

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

    stackView.setCustomSpacing(30.0, after: stackView.subviews[0])
    
    0 讨论(0)
提交回复
热议问题