title: hugging and compression resistance in nested views
body: <p>I'm trying to understand how hugging and compression resistance really work.</p>
  
  <p>I have this scenario where I need two labels on the left (inside the green container) and two labels on the right (inside the blue container).</p>
  
  <p><a href="https://i.stack.imgur.com/X1UPS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/X1UPS.png" alt="enter image description here"></a></p>
  
  <p>As the image shows, I want the green container to hug content (Android's <code>wrap content</code>) and the blue container to fill the remaining space (Android's <code>fill_parent</code>).</p>
  
  <p>I thought I could just add hugging/compression priorities to the green view, like:</p>
  
  <pre><code>greenView.setContentHuggingPriority(
      UILayoutPriorityDefaultHigh, forAxis: .Horizontal)
  greenView.setContentCompressionResistancePriority(
      UILayoutPriorityDefaultHigh, forAxis: .Horizontal)
  </code></pre>
  
  <p>But it seems that it doesn't work as expected. I have to apply those constraints to the (red and yellow) labels instead.</p>
  
  <p>Anyone knows the reason?</p>
  
  <p><strong>Some thoughts (edited):</strong></p>
  
  <p>From Ken's answer it follows that you have to set hugging/compression to the labels instead of container views.</p>
  
  <p>In the example of this question, I would set, for example, a hugging of 750 (High) and a resistance of 1000 (Required) to the labels on the left. Since defaults for labels are hugging of 251 (Low+1) and resistance of 750 (High), the hugging and compression will be greater for the labels on the left (750 > 251 and 1000 > 750). At the same time, the compression will be greater than the hugging within the very labels (1000 > 750).</p>
  
  <p>This way, the labels on the left will try to hug their content, but not as much as to compress it. For example, the red label can't wrap its content completely because the yellow label doesn't want to compress.</p>
  
  <p>Phew!</p>