title: Resize NSView to its subview using auto layout
body: <p>In Interface Builder I've added a <code>NSScrollView</code> with a <code>NSImageView</code>, some labels, a horizontal separator and a <code>NSView</code>. The <code>NSScrollView</code> looks like the following:
  <img src="https://i.stack.imgur.com/suGSm.png" alt="The NSScrollView"></p>
  
  <p>Every element has constraints from the top left, and both the separator and the custom view also have a constraints to the right.</p>
  
  <p>Sometimes I need to change the content of the custom view. I do this with the following code (<code>options</code> is the custom view, <code>view</code> is the view I want to display):</p>
  
  <pre><code>[view setTranslatesAutoresizingMaskIntoConstraints:NO];
  options.subviews = [NSArray arrayWithObject:view];
  
  // Fix the constraints.
  NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(view);
  [options addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:viewsDictionary]];
  [options addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:viewsDictionary]];
  </code></pre>
  
  <p>This works to some extent: the correct content is displayed in the view and the content's width is changed according to the constraints. However, the height of the <code>options</code> view doesn't change, so some content of the <code>view</code> view is not displayed. I tried to change this by manually setting the frame, but that doesn't work. Also, I tried the following to set a constraint:</p>
  
  <pre><code>[options addConstraint:[NSLayoutConstraint constraintWithItem:options attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeHeight multiplier:1 constant:0]];
  </code></pre>
  
  <p>Nothing works though. Does anyone know how I can fix this?</p>
  
  <p>A second problem I noticed is that even when the content of the <code>NSScrollView</code> is larger than the <code>NSScrollView</code> itself, scrolling doesn't work. No scrollbar is displayed. How can I fix that?</p>
  
  <p>I still can't get my head around these harder problems with constraints...</p>