'View resized even after setting contentHuggingPriority to defaultHigh

I have a vertical stackView.

bodyStackView.translatesAutoresizingMaskIntoConstraints = false
bodyStackView.axis = .vertical
bodyStackView.alignment = .fill
bodyStackView.distribution = .fill
bodyStackView.spacing = 8.0
bodyStackView.backgroundColor = .yellow

and two/three views get added to it.

bodyStackView.addArrangedSubview(titleStackView)
bodyStackView.addArrangedSubview(priceStackView)
bodyStackView.addArrangedSubview(subscriptionInEligibleLabel)

titleStackView.setContentHuggingPriority(.defaultHigh, for: .vertical)
priceStackView.setContentHuggingPriority(.defaultLow, for: .vertical)

I want the last or the bottom-most view to stretch. I have set the "ContentHuggingPriority", and yet the first or the top-most view is getting stretched. How do we control this? enter image description here



Solution 1:[1]

It's not clear why you have 3 stack views in your bodyStackView, but assuming you have a valid reason...

You need to set the Content Hugging Priority on the labels, not on the stack views.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DonMag