Я получил UIStackView
ParticipateButtonStackView , управляющий тремя кнопками одного класса: ParticipateButton
Эти кнопки содержат только изображение.Чтобы иметь отступы сверху и снизу, я установил UIEdgeInsets
.Но это свойство и свойство .spacing = 1
не работают одновременно.Почему?
Stackview:
class ParticipateButtonStackView: UIStackView {
//MARK: - Properties & Variables
var delegate: participateButtonStackViewDelegate?
//MARK: - GUI Objects
var buttons: [ParticipateButton]!
let sureButton = ParticipateButton(type: .sure)
let maybeButton = ParticipateButton(type: .maybe)
let nopeButton = ParticipateButton(type: .nope)
//MARK: - Init & View Loading
override init(frame: CGRect) {
super.init(frame: frame)
self.addBackground(color: UIColor.gray)
buttons = [sureButton, maybeButton, nopeButton]
setupStackView()
setupButtons()
}
//MARK: - Setup
func setupStackView() {
self.axis = .horizontal
self.spacing = 1
self.alignment = .leading
self.distribution = .fillEqually
}
func setupButtons() {
for button in buttons {
addArrangedSubview(button)
button.addTarget(self, action: #selector (self.buttonClick(sender:)), for: .touchUpInside)
}
}
}
ParticipateButton
class ParticipateButton: UIButton {
var typeOfButton: participateLists!
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = LebensfitSettings.Colors.buttonBG
self.tintColor = LebensfitSettings.Colors.basicTintColor
self.imageView?.contentMode = .scaleAspectFit
self.contentEdgeInsets = UIEdgeInsets(top: 7, left: 0, bottom: 7, right: 0)
}
convenience init(type: participateLists) {
self.init()
self.typeOfButton = type
setImage(type: type)
}
func setImage(type: participateLists) {
var buttonImage: UIImage?
switch type {
case .sure:
buttonImage = UIImage(named: "pb_sure")?.withRenderingMode(.alwaysTemplate)
[...]
}
self.setImage(buttonImage, for: .normal)
}
}
Это ошибка, которая получаетброшено:
Попытка восстановления путем нарушения ограничения
NSLayoutConstraint: 0x600001adb020 'UISV-интервал' H: [LebensfitFirebase.ParticipateButton: 0x7f9899c5eaa0] - (1)LebensfitFirebase.ParticipateButton: 0x7f9899c5fad0] (активный)>
Редактировать:
participateButtonStackView.leftAnchor = view.leftAnchor
participateButtonStackView.rightAnchor = view.rightAnchor
participateButtonStackView.bottomAnchor = view.bottomAnchor
participateButtonStackView.heightAnchor = equalToConstant(50)