У меня вертикальный UIStackView, и я пытаюсь добавить несколько представлений в представление стека, все с фиксированной высотой 50.
Я установил выравнивание и распределение в представлении стека как Fill для обоих в моей xib.
let button = UIButton()
button.setTitle(card.title, for: .normal)
button.layer.cornerRadius = 10
button.layer.backgroundColor = UIColor.red.cgColor
let damageCardConstraint = button.heightAnchor.constraint(equalToConstant: 50)
damageCardConstraint.isActive = true
// let label = UILabel()
// label.text = $0.title
self?.damageCardView.addArrangedSubview(button)
Я ожидаю, что представления будут добавлены в представление стека с фиксированной высотой 50. Вместо этого я получаю представление, высота которого заполняет высоту представления стека (высота равна 200). Я также получаю это в консоли
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x600002288140 UIStackView:0x7f894df03c50.height == 400 (active)>",
"<NSLayoutConstraint:0x60000228b0c0 UIButton:0x7f894dd0ed90'Wounded Pilot'.height == 50 (active)>",
"<NSLayoutConstraint:0x60000228b070 'UISV-canvas-connection' UIStackView:0x7f894df03c50.top == UIButton:0x7f894dd0ed90'Wounded Pilot'.top (active)>",
"<NSLayoutConstraint:0x60000228b570 'UISV-canvas-connection' V:[UIButton:0x7f894dd0ed90'Wounded Pilot']-(0)-| (active, names: '|':UIStackView:0x7f894df03c50 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000228b0c0 UIButton:0x7f894dd0ed90'Wounded Pilot'.height == 50 (active)>
Похоже, что добавленное мною ограничение нарушается. Я не уверен, какое ограничение я должен удалить, чтобы решить мою проблему.