title: UICollectionView cell borders in a flow layout
body: <p>I'm using UICollectionView to lay out a bunch of cells that are sectioned by first letter of their title. Each cell should have a very thin border around it, and the section headers should have borders above and below. Here's my current prototype:</p>
  
  <p><img src="https://i.stack.imgur.com/X4GRp.png" alt="Grid of large equally-sized cells, four to a row, with slim light gray headings between sections. Narrow gray borders show the edges of the cells and dividers."></p>
  
  <p>I achieve the current appearance with the following rules:</p>
  
  <ol>
  <li>Stroke the right and bottom edge of each cell.</li>
  <li>Stroke the bottom edge of each section heading.</li>
  </ol>
  
  <p>This is very close to what I want, but there are two defects:</p>
  
  <ol>
  <li>If the line before a section heading isn't full, then the border along the top of the heading stops short of the right edge of the screen.</li>
  <li>It's not visible in this screenshot, but if a line <em>is</em> full, the right border of the last cell in the line is still drawn, which looks a little odd against the edge of the screen.</li>
  </ol>
  
  <p>My best idea to fix this is to somehow tell each cell if it's in the last row of a section or the last cell in a row; then the cell would turn off the offending borders, section headings would draw a top border as well as a bottom, and everything would be hunky-dory. I don't know how to achieve that, though.</p>
  
  <p>Any thoughts on how to manage that, or another way to get the look I'm going for? I'm currently using a UICollectionViewFlowLayout.</p>