Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

macOS NSStackView content does not fill the available space

Tags:

macos

cocoa

I use a NSStackView to dynamically (added by code) display other NSViews, everything works so far, but the sub views are to small.

They try to be as small as possible, regardless the constrains, if i resize the views in IB, they scale correctly

The Header with the hide button does not fill the available space:

enter image description here

I did set the translatesAutoresizingMaskIntoConstraints property to false on the stackview and all subviews

like image 451
Stoneburner Avatar asked Oct 16 '25 16:10

Stoneburner


1 Answers

Well, it's hard to know for sure without more information, but the most likely cause is that the horizontal content hugging priority of the labels is higher than the horizontal hugging priority of the stack view. (Note: the former is a general property of all views while the latter is a stack-view-specific property.)

You also need to have constraints between the stack view and its superview to make the stack view stretch the full width. For example, leading and trailing space constraints.

like image 121
Ken Thomases Avatar answered Oct 18 '25 07:10

Ken Thomases



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!