iOS autolayout, how to make View wraps content?

Please follow the logic below. It should get you through your problem:

  1. The first thing you need to do is make your Labels wrap their content. You can follow Mark's suggestion to do this here

  2. Save a reference to the height constraint of your ContainerView from your Storyboard or .xib file

  3. Update the height constraint with an appropriate height every time after you update the content of the two labels

This worked for me in a similar situation. You also have to add all the constraints up down left right for the ContainerView to fit in the RootView


Think about that,

If you want height to wrap content, give height to "0" with greater condition view.height >= 0

if you want width , to same thing for width... so that view keeps minimum sizing

Tags:

Ios

Autolayout