Overriding shouldInvalidateLayout(forBoundsChange:) is easy. shouldInvalidateLayout(forBoundsChange:).We need to override three methods of the UICollectionViewFlowLayout class: Create a new class, name it StickyHeadersCollectionViewFlowLayout, and make sure it inherits from UICollectionViewFlowLayout. To implement sticky section headers, we need to create a UICollectionViewFlowLayout subclass. The star player of this tutorial is the UICollectionViewFlowLayout class. The section headers are given a random color to make it easier to see the effect of the sticky section headers. If you build and run the application, you notice that the collection view mimics a table view. To get us started, I created a sample application that you can clone or download from GitHub. It is UICollectionViewFlowLayout we need to subclass to add sticky section headers. It is no coincidence that these properties are members of the UICollectionViewFlowLayout class. Since iOS 9, the UICollectionViewFlowLayout class has two properties, sectionHeadersPinToVisibleBounds and sectionFootersPinToVisibleBounds, that make it very easy to make section headers and section footers sticky. If your project targets iOS 9 or higher, then you are in luck. Adding them to a collection view requires a bit of extra work. Sticky section headers, for example, are built into table views. UITableView, on the other hand, has more configuration options, but it is harder to customize. Even though UICollectionView is incredibly flexible and versatile, trivial things are sometimes difficult to accomplish.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |