I have a horizontal UIStackView
with some arranged subviews, whose heights should be less than that of the StackView but centered along the StackView's y axis. However, even after setting constraints on the subviews, their height does not change and is equal to that of the StackView.
Apart from setting constraints defining the subviews' heights and setting their y axis to that of the UIStackView, I've set the StackView's alignment to center, and its distribution to "fill proportionally" - these have all been recommended in answers to similar questions, but none of them change the subviews' height.
I've also tried setting the StackView's directionalLayoutMargins
, which both the top and bottom margins set to (height of the StackView - height of the arranged subviews) / 2, and all this does is shift the subviews far below the StackView's center y axis and, if I set the bottom margin to 0, squish the subviews.
Here are my constraints:
button.widthAnchor.constraint(equalToConstant: width),
button.heightAnchor.constraint(equalToConstant: 32),
button.centerYAnchor.constraint(equalTo: contentView.stackView.centerYAnchor)