Swift 在底部锚定两个按钮,一左一右

Swift Anchor two buttons on bottom, one on left and one on right

我需要以编程方式向现有视图添加两个按钮,我需要一个按钮在左下角,一个在右下角。我可以添加正确的,但我不知道如何添加左侧的。 在我的适用于右键的代码下方。我可以在左侧添加另一个按钮吗?

   private func constrainFloatingButtonToWindow() {
    DispatchQueue.main.async {
        guard let keyWindow = UIApplication.shared.windows.first(where: { [=11=].isKeyWindow }),
            let floatingButton = self.floatingButton else { return }
        keyWindow.addSubview(floatingButton)
        keyWindow.trailingAnchor.constraint(equalTo: floatingButton.trailingAnchor,
                                            constant: self.trailingValue).isActive = true
        keyWindow.bottomAnchor.constraint(equalTo: floatingButton.bottomAnchor,
                                          constant: self.trailingValue).isActive = true
        floatingButton.widthAnchor.constraint(equalToConstant:
            DataTableViewController.buttonWidth).isActive = true
        floatingButton.heightAnchor.constraint(equalToConstant:
            DataTableViewController.buttonHeight).isActive = true
    }
}

添加此约束:

yourView.addSubview(yourButton)
yourButton.leadingAnchor.constraint(equalTo: yourView.leadingAnchor).isActive = true
yourButton.bottomAnchor.constraint(equalTo: yourView.safeAreaLayoutGuide.bottomAnchor).isActive = true
yourButton.heightAnchor.constraint(equalToConstant: 50).isActive = true // sostituisci il valore con quelli tuoi
yourButton.widthAnchor.constraint(equalToConstant: 200).isActive = true