How to make buttons fill vertically in a NSStackView with a fixed height

1.8k views Asked by At

enter image description here

The NSStackView shown above has top/leading/trailing constraints, a proportional height to its superview, and is set to Align Top and Fill Equally. I want to have the buttons stretch vertically to fill the height of their stack view. How can I configure this with a NSStackView? Or do I have to add constraints on the buttons?

2

There are 2 answers

0
elce On BEST ANSWER

I solved my problem by setting top/bottom constraints on the buttons to the stack view. I don't think there is a way to configure an NSStackView to do what I want.

So a UIButton fills the height of the UIStackView if the UIStackView's alignment is set to fill. An NSStackView does not have a fill property for alignment and AFAIK, can't make an NSButton do the same thing

0
Darrarski On

As you already noticed, it's not possible using NSStackView. It lacks fill alignment, available for UIStackView.

However, there is a much more powerful UI component in AppKit:

NSGridView - https://developer.apple.com/documentation/appkit/nsgridview

You can customize alignment for each row and column, including "fill" mode.