title: UIScrollView autolayout - vertical scroll only
body: <p><code>UIScrollView</code> is a little special in the way it interprets auto layout constraints, as geometry of the subviews fills its <code>contentSize</code> as opposed to <code>frame</code>/<code>bounds</code>. Apple has a nice write up on the matter here: <a href="https://developer.apple.com/library/ios/technotes/tn2154/_index.html" rel="nofollow">https://developer.apple.com/library/ios/technotes/tn2154/_index.html</a></p>
  
  <p>The problem I'm facing is when I try in place multiline labels into the <code>scrollView</code>. </p>
  
  <p>An example constrain looks like this:</p>
  
  <pre><code>scrollView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-20-[image(==imageWidth)]-15-[captionLabel]|", options: .AlignAllCenterY, metrics: metrics, views: views))
  </code></pre>
  
  <p>I'm not showing additional subviews that are handled by other <code>scrollView.addConstraints()</code> calls which take up more vertical space.</p>
  
  <p>Ideally, I want both elements to fit horizontally within the screen, and have the <code>captionLabel</code> break into multiple lines as necessary. Instead, the whole text is rendered into a single line and the <code>scrollView</code> sets its <code>contentSize</code> to accommodate the larger width.</p>
  
  <p>What options are there to solve with auto layout?</p>
  
  <p><em>Edit</em>: Not too happy about nesting more contentViews, so I ended up setting the desired width of the label in a separate constraint, and updating it in <code>viewWillTransitionToSize</code>. In my case, a whole list of similar "rows" of labels in used, and only the first one has width set through a calculated constraint, the rest are set to be equal to the first.</p>