Question

I've started using AutoLayout in my apps and I've searched around and I'm still a little confused about dynamic height of UILabels and UITextViews. Is there a way in interface builder to set the constraints so that I can have a dynamic height on labels and text views and cause the subviews below the label or text view to automatically move down when the height adjusts? Or at the least cause the textview or label or change its font size so that all of the text can fit within the given space provided by the constraints. If anyone has any insight on this it would be awesome!

Was it helpful?

Solution

Yes, there is a way. Say you have two labels - LabelA and LabelB underneath it.

Set the following constraints:

  • Left edge for LabelA and LabelB
  • Width for LabelA and LabelB
  • Distance between bottom edge of LabelA and top edge of LabelB

Make sure you also set number of lines to 0 on both of them if you want then to automatically grow.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top