ios - UICollectionView cell borders in a flow layout -


i'm using uicollectionview lay out bunch of cells sectioned first letter of title. each cell should have thin border around it, , section headers should have borders above , below. here's current prototype:

grid of large equally-sized cells, 4 row, slim light gray headings between sections. narrow gray borders show edges of cells , dividers.

i achieve current appearance following rules:

  1. stroke right , bottom edge of each cell.
  2. stroke bottom edge of each section heading.

this close want, there 2 defects:

  1. if line before section heading isn't full, border along top of heading stops short of right edge of screen.
  2. it's not visible in screenshot, if line is full, right border of last cell in line still drawn, looks little odd against edge of screen.

my best idea fix somehow tell each cell if it's in last row of section or last cell in row; cell turn off offending borders, section headings draw top border bottom, , hunky-dory. don't know how achieve that, though.

any thoughts on how manage that, or way i'm going for? i'm using uicollectionviewflowlayout.

i ended subclassing uicollectionviewflowlayout , applying several heuristics after flow layout had calculated attributes each cell:

  1. if center.y equal center.y of last item in section, cell in last row of section.
  2. if cgrectgetmaxy(frame) equal cgrectgetmaxy(self.collectionview.bounds), cell agains right edge of collection view.

i stored results of these calculations in subclass of uicollectionviewlayoutattributes, , wrote uicollectionviewcell subclass -applylayoutattributes: method adjust borders background view draws based on additional properties.

i've put whole mess fairly enormous gist can see did. happy hacking.


Comments