title: Autolayout - stretching a view to fill its parent view
body: <p>I noticed some very strange behavior when trying to fill a view with a child view using autolayout. The idea is very simple: add a subview to a view and make it use all of the width of the parent view.</p>
  
  <pre><code>NSDictionary *views = @{
                          @"subview":subView,
                          @"parent":self
                         };
  </code></pre>
  
  <p>This does not work:</p>
  
  <pre><code>[self addConstraints:
        [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[subview]|" 
                                                options:0 
                                                metrics:nil 
                                                  views:views]];
  </code></pre>
  
  <p>The subview doesn't use the full width of the parent view.</p>
  
  <p>But this works:</p>
  
  <pre><code>[self addConstraints:
        [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[subview(==parent)]|" 
                                                options:0 
                                                metrics:nil 
                                                  views:views]];
  </code></pre>
  
  <p>I would expect that both would work as intended. So why is the first example not working? It is what Apple recommends in the following technical note:</p>
  
  <p><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><strong>EDIT</strong>: (removed irrelevant information)</p>