title: Evenly spacing several rows of an arbitrary number of elements using NSLayoutConstraints
body: <p>I have a question about using layout constraints for the following scenario. Everything is in code (no nibs or storyboards). I want to create a view that contains an arbitrary number of rows of items. Each row contains an arbitrary number of subviews.  </p>
  
  <p>To create this view, I want to pass in an array that is two levels deep. The first level array contains each row. The second level array contains the elements in each row. So, for example, this might look like this:</p>
  
  <p><code>NSArray *elements = @[@[subview1, subview2, subview3], @[subview4], @[subview5, subview6]]</code></p>
  
  <p>In this array, there would be 3 rows: </p>
  
  <p>1) Row 1: subview1, subview2, subview3<br>
  2) Row 2: subview4<br>
  3) Row 3: subview5, subview6<br></p>
  
  <p>I want these elements to be formatted as:</p>
  
  <p>-The rows should all be the full width of their parent view (for this we can assume it's the size of the screen)<br>
  -Each of the elements in a row should be the same width and have the same amount of space between them (say if there are 4 elements, the space between 1&amp;2 and 2&amp;3 could be 10pt)<br>
  -Each of the rows should have the same amount of vertical space between them (e.g. 10pt vertical space between each row)<br></p>
  
  <p>In the scenario above, row 1 would have 3 subviews with equal width equally spaced apart, row 2 would have 1 subview which takes up the full width of the row, and row 3 would have 2 subviews that have equal width and would be equally spaced apart.</p>
  
  <p>So, the question is, how do I do this?!</p>
  
  <p>I've been working on this for awhile and my understanding doesn't seem to be getting any better. Help would be appreciated!</p>