title: How do I use NSLayoutConstraint to make a subview take up remaining/total height of superview
body: <p>I have a superview to wich I add two subviews (subview1 and subview2).</p>
  
  <p>I want subview1 to have same width as superview and stretch with superview and also have a height of 30px and align to the top of superview. This I can get working with the following code:</p>
  
  <pre><code>NSDictionary *metrics = @{@"height":[NSNumber numberWithFloat:30.0f]};
  NSDictionary *views = NSDictionaryOfVariableBindings(subview1);
  NSArray *tabContainerConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[subview1(==height)]" options:NSLayoutFormatAlignAllTop metrics:metrics views:views];
  [superview addConstraints:tabContainerConstraints];
  
  metrics = nil;
  tabContainerConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[subview1]|" options:(NSLayoutFormatAlignAllLeading | NSLayoutFormatAlignAllTrailing) metrics:metrics views:views];
  [superview addConstraints:tabContainerConstraints];</code></pre>
  
  <p>Then I want subview2 to also have same width as superview and stretch with superview and also I want subview2 to align its top to subview1's bottom and then I want subview2 to fill all of the remaining height of superview (align bottom to bottom) and stretch in height with superview. I try to do this with this code:</p>
  
  <pre><code>NSDictionary *metrics = nil;
  NSDictionary *views = NSDictionaryOfVariableBindings(subview2);
  NSArray *tabContainerConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[subview2]|" options:(NSLayoutFormatAlignAllLeading | NSLayoutFormatAlignAllTrailing) metrics:metrics views:views];
  [superview addConstraints:tabContainerConstraints];
  
  views = NSDictionaryOfVariableBindings(subview1, subview2);
  tabContainerConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[subview1][subview2]-0-|" options:0 metrics:metrics views:views];
  [superview addConstraints:tabContainerConstraints];</code></pre>
  
  <p>But strange things happens... subview is always aligned to with its top to subview1's bottom and also has the full width of superview so this is good. But height is strange... When first drawn/displayed subview2 has a very limited height, somewhere between 20-30 pixel it seems, but I can force a redraw by switching to another tab/view and back and then it is drawn in full/correct height. My subview2 is a NSTextView, and when I type in text strange things happen, my subview2 suddenly does not take up all height and is no longer aligned with the bottom of superview.</p>
  
  <p>I hope my explanation is ok, if not please ask any question. Any ideas on how to fix this? I thought the |-0-[view]-0-| would do the trick?</p>
  
  <p>Thank you<br>
  Søren</p>