Wednesday, July 12, 2017

UICollectionView Sticky Headers & Footers

From iOS 9, UICollectionViewFlowLayout has two very handy properties to pin the header & footer to the top/bottom of the collection view bounds

1. sectionHeadersPinToVisibleBounds

When this property is true, section header views scroll with content until they reach the top of the screen, at which point they are pinned to the upper bounds of the collection view. Each new header view that scrolls to the top of the screen pushes the previously pinned header view offscreen. 

2. sectionFootersPinToVisibleBounds

When this property is true, section footer views scroll with content until they reach the bottom of the screen, at which point they are pinned to the lower bounds of the collection view. Each new footer view that scrolls to the bottom of the screen pushes the previously pinned footer view offscreen.