I have a horizontal stack view with 3 buttons: Backwards, Play, Forward for a music application. Here is my current code:
self.controlStackView.axis = .horizontal
self.controlStackView.distribution = .equalSpacing
self.controlStackView.alignment = .center
self.controlStackView.spacing = 10.0
self.controlStackView.translatesAutoresizingMaskIntoConstraints = false
self.contentView.addSubview(self.controlStackView)
self.controlStackView.topAnchor.constraint(equalTo: self.artworkImageView.bottomAnchor, constant: 10.0).isActive = true
self.controlStackView.centerXAnchor.constraint(equalTo: self.contentView.centerXAnchor).isActive = true
What does this is it distributes the button as follows (from the center due to alignment):
[backward] - 10 spacing - [play] - 10 spacing - [forward]
I could increase the spacing but it would still be fixed. So I'm setting the leading and trailing anchor to define a maximum width of the stack view:
self.controlStackView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
self.controlStackView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
What this does to the layout:
[left edge backward] - lots of spaaaaaaace - [centered play] - lots of spaaaaaaace - [right edge forward]
It distributes over the entire width (and there is an .equalSpacing between center to the left and right). But this also is not helpful. Essentially my goal is to have true equal spacing including the edges.
Let's say I have an available width of 100 and my 3 buttons are 10, 20, 10 - which means that there is 60 remaining space that is empty.
I would like it to be distributed like this:
space - [backward] - space - [play] - space [forward] - space
So 4 spaces in between my buttons each space being 15, so we fill the 60 remaining space. I could of course implement padding to the stack view to get the outer space, but this would be quite static and is not equally distributed.
Does anybody know if I can implement it this way that the edges are included into the space distribution?
Thanks