无法在UIStackView中设置编程布局约束条件
问题描述:
我正在尝试通过故事板创建的UIStackView中的单选按钮。但是,基于Firebase中的数据以编程方式在UIStackView中创建单选按钮。无法在UIStackView中设置编程布局约束条件
我使用DLRadioButtons提供的库。
UIStackView以下标签,命名radioStackView:其中单选按钮基于火力地堡数据相加
代码:
`
pollRef.observe(FIRDataEventType.value, with: {(snapshot) in
self.numberOfChildren = Int(snapshot.childSnapshot(forPath: "answers").childrenCount)
self.passLabel.text = String(self.numberOfChildren)
print(self.numberOfChildren)
var buttons = [DLRadioButton]()
for x in 0..<self.numberOfChildren {
let answerLabel = snapshot.childSnapshot(forPath: "answers").childSnapshot(forPath: String(x+1)).childSnapshot(forPath: "answer").value
let firstRadioButton = self.createRadioButton(frame: CGRect(x: 1, y:1 , width: 80.0, height: 1.0), title: answerLabel as! String, color: UIColor.black)
firstRadioButton.tag = x
firstRadioButton.translatesAutoresizingMaskIntoConstraints = false
buttons.append(firstRadioButton)
let margins = self.radioStackView.layoutMarginsGuide
firstRadioButton.topAnchor.constraint(equalTo: margins.topAnchor, constant: 5).isActive = true
self.radioStackView.addArrangedSubview(firstRadioButton)
}
let groupButtons = DLRadioButton()
groupButtons.otherButtons = buttons
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
感谢您的帮助,我已经更新了代码。我不能让按钮直接堆叠在一起。有什么想法吗? – tccpg288
检查[间距](https://developer.apple.com/reference/uikit/uistackview/1616225-spacing)属性 –
我使用界面生成器,我正在使用这些设置并且间距没有改变。 – tccpg288