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

时间:2016-11-19 22:28:48

标签: ios swift uistackview

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

2 个答案:

答案 0 :(得分:9)

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

答案 1 :(得分:2)

如果您有自定义 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
  }
}