title: Proper usage of intrinsicContentSize and sizeThatFits: on UIView Subclass with autolayout
body: <p>I'm asking this (somehow) simple question just to be finicky, because sometimes I'm worried about a misuse I might be doing of many UIView's APIs, especially when it comes to autolayout.</p>
  
  <p>To make it super simple I'll go with an example, let's assume I need an UIView subclass that has an image icon and a multiline label; the behaviour I want is that the height of my view changes with the height of the label (to fit the text inside), also, I'm laying it out with Interface builder, so I have something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/P5GvC.png" alt="simple view image"></p>
  
  <p>with some constraints that give fixed width and height to the image view, and fixed width and position (relative to the image view) to the label:</p>
  
  <p><img src="https://i.stack.imgur.com/XsKSt.png" alt="simple view image, constraints shown"></p>
  
  <p>Now, if I set  some text to the label, I want the view to be resized in height to fit it properly, or remain with the same height it has in the xib.
  Before autolayout I would have done always something like this:</p>
  
  <p>In the CustoView subclass file I would have overridden <code>sizeThatFits:</code> like so:</p>
  
  <pre><code>- (CGSize) sizeThatFits:(CGSize)size{
  
      //this stands for whichever method I would have used
      //to calculate the height needed to display the text based on the font
      CGSize labelSize = [self.titleLabel intrinsicContentSize];
  
      //check if we're bigger than what's in ib, otherwise resize
      CGFloat newHeight = (labelSize.height &lt;= 21) ? 51: labelSize.height+20;
  
      size.height = newHeight;
  
      return size;
  
  }
  </code></pre>
  
  <p>And than I would have called something like:</p>
  
  <pre><code>myView.titleLabel.text = @"a big text to display that should be more than a line";
  [myView sizeToFit];
  </code></pre>
  
  <p>Now, thinking in constraints, I know that autolayout systems calls <code>intrinsicContentSize</code> on the view tree elements to know what their size is and make its calculations, therefore I should override <code>intrinsicContentSize</code> in my subview to return the exact same things it returns in the <code>sizeThatFits:</code> method previously shown, except for the fact that, previously, when calling <code>sizeToFit</code> I had my view properly resized, but now with autolayout, in combination with a xib, this is not going to happen.</p>
  
  <p>Of course I might be calling <code>sizeToFit</code> every time I edit text in my subclass, along with an overridden <code>intrinsicContentSize</code> that returns the exact same size of <code>sizeThatFits:</code>, but somehow I don't think this is the proper way of doing it.</p>
  
  <p>I was thinking about overriding <code>needsUpdateConstraints</code> and <code>updateConstraints</code>, but still makes not much sense since my view's width and height are inferred and translated from autoresizing mask from the xib.</p>
  
  <p>So long, what do you think is the cleanest and most correct way to make exactly what I show here and support fully autolayout? </p>