How to make view take up full width in vertical NSStackView

Issue #172

https://stackoverflow.com/questions/51644692/nsstackview-subviews-not-resizing-sub-stack-views/55220837#55220837

If you want child view inside vertical NSStackView to fill its parent width, then reduce contentCompressionResistancePriority

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
myChildView.translatesAutoresizingMaskIntoConstraints = false
myChildView.setContentCompressionResistancePriority(
NSLayoutConstraint.Priority(rawValue: 1),
for: .horizontal
)

NSLayoutConstraint.activate([
myChildView.heightAnchor.constraint(equalToConstant: 50)
])

NSAnimationContext.runAnimationGroup({context in
context.duration = 0.25
context.allowsImplicitAnimation = true
stackView.insertArrangedSubview(myChildView, at: 1)

view.layoutSubtreeIfNeeded()
}, completionHandler: nil)

Updated at 2020-11-20 16:11:11

Comments