5
votes

I have a horizontal StackView with distribution as "fill equally". It has 3 labels. I want one of the labels to have dynamic height. When I set the number of number of lines to 0 for that label, it ends up breaking the constraint the spacing constraint at runtime.

All these horizontal stackviews make a one vertical stackview. I have tried setting lower vertical hugging priority and higher resistance priority to the multiline label

Also it behaves like this in the XIB

Before changing the number of lines enter image description here

After changing the number of lines enter image description here

3
Have to set the Content Compression Resistance and Hugging Priority? - Bista
Desired output? imgur.com/a/tWi2M - Bista
Yes, I need the same output. - AjinkyaSharma

3 Answers

5
votes

You do not need to set Content Hugging and Compression resistance property to achieve that effect.

  1. Horizontal Stack Views: Set Alignment "Fill" & Distribution "Fill Equally"

  2. Vertical Stack View: Set Alignment "Fill" & Distribution "Fill"

  3. Set Label Lines to 0.

  4. Set Top, Bottom, Leading Constraint for Vertical Stack View.

0
votes

Set all constraints for UIStackView. Update the UIStackview height constraints constant value based on UILabel text height

0
votes

Not Directly answering the question rather on how to control the dynamic height of UIStackView.

  1. Vertical Stack View. Make it free of height like no bottom constraints or no height constraints.
  2. Contents(like view) are fixed height.
  3. Both Alignment & Distribution of UIStackView will "fill"

now show or hide the contents then Stactview height will dynamically change.