title: Correct approach (in autolayout) to resize superview and re-layout subviews?
body: <p>I'm trying to make sense of an autolayout issue. I have a small custom view that itself has an imageView and a couple of labels. The image is fetched from a server and includes some metadata to help the app determine where the text should be placed. For now, I just need to limit the width of the labels (triggering word wrap) to avoid putting text over top of a logo in the background.</p>
  
  <p>To make this easier, I thought I could create a containing view for the two labels. That way, I could resize the container and (I thought) the sub-views would follow suit.</p>
  
  <p><img src="https://i.stack.imgur.com/KaZe9.png" alt="Screenshot from Xcode"></p>
  
  <p>I'm pretty sure I have the constraints set up correctly, because it all works OK until I start fiddling with the frame:</p>
  
  <p><img src="https://i.stack.imgur.com/Cj1Bn.png" alt="Image before fiddling"></p>
  
  <p>When the image is fetched from the server, I resize the frame as follows:</p>
  
  <pre><code>CGRect frame = self.labelContainerView.frame;
  frame.size.width = my_limited_width;
  self.labelContainerView.frame = frame;
  </code></pre>
  
  <p>And I can see that the container itself has been resized, but its child views haven't:</p>
  
  <p><img src="https://i.stack.imgur.com/z7ecR.png" alt="Resized container with un-resized child views"></p>
  
  <p>To try to trigger the layout, I've done:</p>
  
  <pre><code>[self.labelContainerView setNeedsLayout];
  [self.labelContainerView layoutIfNeeded];
  </code></pre>
  
  <p>... but this ends up just restoring the original constraints from the .xib. That's a handy feature and all... and it's one that I might need... but not what I need here.</p>
  
  <p>I've seen posts that hint that resizing frames is the wrong thing to do here; that you should get a handle on the appropriate constraint and fiddle with it instead. I tried that:</p>
  
  <pre><code>self.rightMarginConstraint.constant = 150;
  </code></pre>
  
  <p>... and it almost works:</p>
  
  <p><img src="https://i.stack.imgur.com/MQUIb.png" alt="Adjusted constraint on right edge of superview"></p>
  
  <p>But in this case, that first (larger) label never grows beyond two lines, even if its height constraint is set to be &lt;= something ridiculously huge. The layout system isn't re-computing how many lines the label will need.</p>
  
  <p>Obviously I don't understand enough about the way views, frames, and autolayout work together to be able to see the solution for myself, which is why I'm asking here. What's the correct way to solve this problem?</p>