Reputation: 551
I have 2 horizontal NSStackViews within 1 vertical NSStackView within a NSView. It seems I cannot resize the whole view even with the constraints. If I increase the width by dragging the IB view handle the views will grow. But is seems if I try to shrink them by pulling the IB view handles towards each other the stack views stop shrinking the parent view width is 800 pix. Is there a way to fix this?
Upvotes: 1
Views: 1258
Reputation: 48205
If you want child view inside vertical NSStackView
to fill its parent width, then reduce contentCompressionResistancePriority
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)
Upvotes: 1
Reputation: 551
After adding a single single horizontal NSStackView (previous comment), I then added two vertical NSStackViews then set the content compression resistance priority to the lowest setting (250).
Upvotes: 0