我正在使用库DLRadioButton创建一组单选按钮,并希望该组居中,就在ViewController的底部边缘之外。
我正在尝试使用程序化约束,以便确保在每台设备上正确呈现无线电组:
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: self.view.center.x, y: CGFloat(x)*32, width: 100.0, height: 120.0), title: answerLabel as! String, color: UIColor.green)
firstRadioButton.tag = x
buttons.append(firstRadioButton)
self.view.addSubview(firstRadioButton);
}
let groupButtons = DLRadioButton()
let margins = self.view.layoutMarginsGuide
**groupButtons.bottomAnchor.constraint(equalTo: margins.bottomAnchor, constant: 20).isActive = true**
groupButtons.otherButtons = buttons
})