Search code examples
swiftxcodeviewuikit

Swift - why elements don't have equal sizes?


I have a Vertical Stack View on my screen (Alignment = Fill, Distribution = Fill).

In it there are from top to bottom:

  1. Label (no constraints)
  2. Vertical Stack View (height=21)
  3. Horizontal Slider (height=21)
  4. Label (no constraints)

I was expecting that both my labels (elements 1 &4) will be of equal size and will occupy the majority of the screen and 2nd & 4th elements therefore would be in the center of the screen. But in reality my bottom Label's height is sufficient only to fill it's text while my top Label takes the majority of the space.

I tried to change the Distribution of my Stack View to Fill Proportionally, but in that case my top label becomes smaller than the bottom one.

Why is it happening? How can I make my Labels to become of equal height?

enter image description here

enter image description here

PS I noticed a warning about Content Priority Ambiguity but I can't figure out what should I do about it

enter image description here


Solution

  • To make both labels equal in height I had to select both of them and add a constraint Equal Heights. enter image description here

    Warning about Content Priority Ambiguity was not about them, it was about horizontal labels. To remove warning while keeping their placement I changed Distribution of the horizontal Stack View to Equal Centering.