以编程方式在 Stackview 上设置间距

Programmatically Set Spacing on Stackview

正如标题所说,我四处搜索但没有运气。是否可以将堆栈视图连接到 .swift 文件,然后以编程方式调整间距?谢谢!

let stackView = UIStackView()
stackView.spacing = 10.0      // or whatever you like

如果您有自定义 UIStackView

class YourCustomSublcass {
  //MARK: Initialization of the stackView
  override init(frame: CGRect) {
    super.init(frame: frame)
    self.spacing = 8.0
  }

  required init(coder :NSCoder){
    super.init(coder: coder)
    self.spacing = 8.0
  }
}