I have some issue about my stackview contraints or imageview constraints ı dont know actually.Probably both . This is my stackview constraints stackViewConst and this my imageview constraints imaviewConstraints . When ı try to run ı expect everything looks awesome however unfortunately ı get this screen screen my stackview is lost.How ı can figure out this help me
-
What happens if you also add stackview height constraint ? – Mr.SwiftOak Jan 18 '22 at 11:11
-
Thanks for advice it worked perfectly.But ı cant figure out something.Why is it worked what is the reason.Can you explain me @Mr.SwiftOak – Sait47 Jan 18 '22 at 11:32
-
Setting the vertical compression resistance of the UILabels to .required (1000) might also do the trick. But just a guess since I cannot say anything about the rest of the layout – Daniel Marx Jan 18 '22 at 11:37
-
Thanks for advice this method is also worked .But ı wondering about why is worked plz explain to me . Why do you think like that . I am new in swift so sorry for that multiple questions ı just wanna have knowledge wihout any memorization @DanielMarx – Sait47 Jan 18 '22 at 11:54
-
@Sait47 I added some explanation into the answer below. – Mr.SwiftOak Jan 18 '22 at 11:55
-
https://betterprogramming.pub/what-are-content-hugging-and-compression-resistance-in-swift-60275f6dc69e might give you some insights – Daniel Marx Jan 18 '22 at 12:06
-
Thanks for everything bro.Love you too @DanielMarx – Sait47 Jan 18 '22 at 12:08
-
@Sait47 Sure, no problem! I would however also appreciate if you accept my answer, so that it will be counted into my personal stackoverflow rating. Many thanks in advance. – Mr.SwiftOak Jan 18 '22 at 12:21
-
I have already approved your answer ahhah @Mr.SwiftOak – Sait47 Jan 18 '22 at 13:30
-
@Sait47 This link shows what I actually meant. https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 – Mr.SwiftOak Jan 18 '22 at 13:48
1 Answers
Answer: add stackview height constraint
(or add stack view content resistence and content hugging priorities higher than those of your UIImageView
)
Explanation:
Since you are using storyboard's Interface builder (IB) for creating constraints, as opposed to pure code. The IB uses feature of auto-constraints, which basically means that the IB can figure itself the layout and constraints based on what is displayed in your storyboard. The UIStackView
is using some dynamic resizing (so that elements within stackview are properly layed out) and it is always good idea to give it size constraints, or at least size constraints to elements inside UIStackView
, otherwise it might decide that every element has size of CGSize(height:0,width:0)
You can also make priorities of your UIStackView
higher than those of your UIImageView
so that IB would prioritize the size of your stackview
's constraints to those of your imageView

- 1,469
- 3
- 8
- 19