GitHub Repo: Source Code
Check the code inside FirstViewController
Explanation:
Step 1:
Change the constraint of StackView, such that height >= minValue value. After that it's height will auto adjust depending on the height of the UILabel.
Step 2:
Call sizeToFit method of the UILabel after you set it's text. That will change the frame of the UILabel.
lable.text = "SomeText Here. It will expalnd the StackView.omeText Here. It will expalnd the StackView.omeText Here. It will expalnd the StackView.omeText Here. It will expalnd the StackView.omeText Here. It will expalnd the StackView.omeText Here. It will expalnd the StackView.omeText Here. It will expalnd the StackView.omeText Here. It will expalnd the StackView."
lable.sizeToFit()
Step 3:
Set the Scale Mode of image to Aspect Fit, and set it's height and width constraint.
Step 4:
Set the alignment of Stackview as per the requirement, I have set set it to top to make the image and Label to stay at the top.
Final Result:
Constraints: