title: UIStackView: control of spacing
body: <p>I need to have X number of buttons in a horizontal <code>UIStackView</code>, which resides inside an <code>UIScrollView</code>. The requirement is that the buttons should be evenly distributed in the stack view, and as the number of buttons increases I should reduce the spacings to make them fit into the width of the screen, but there's a minimum spacing, when spacing's reduced and reached the minimum spacing, the buttons can extend beyond the width of the screen.</p>
  
  <p>For example, when I have three buttons I want to layout them like</p>
  
  <p><code>|B1     B2     B3|</code></p>
  
  <p>When I have five buttons (assume they can still fit the width of the screen with less spacing):</p>
  
  <p><code>|B1 B2 B3 B4 B5|</code></p>
  
  <p>But when I have six buttons and have to keep the minimum spacing, I want to stack view to scroll inside its container <code>UIScrollView</code>.</p>
  
  <p>Looking at the doco of <code>UIStackView</code>, the property <code>spacing</code> is:</p>
  
  <p>"The spacing property determines the minimum spacing between arranged views."</p>
  
  <p>So I could use it for the minimum spacing requirement, but for the first example where I have three items, I guess I need to define the stack view's size as well as position, as described in doco:</p>
  
  <p>"Define the stack’s size along its axis. In this case, pin both edges of the stack along it’s axis to its superview, defining the stack view’s size in that dimension. You also need to pin one of the other edges to define the stack view’s position. The stack view sizes and positions its content along its axis to fill the defined space; however, the unpinned edge moves freely, based on the size of the largest arranged view."</p>
  
  <p>But now the problem is:</p>
  
  <ol>
  <li>how to I layout the three buttons, one at left edge, one in the middle and one at the right edge?</li>
  <li>when I have more items that couldn't fit into the width of screen, how do I determine that I should <strong>not</strong> pin the stack view's right edge to the right of its superview, so its size can grow?</li>
  </ol>
  
  <p>Thanks!</p>