How to make Supplementary View float in UICollectionView as Section Headers do in UITableView plain style

后端 未结 13 736
逝去的感伤
逝去的感伤 2020-11-27 09:35

I\'m struggling to achieve a \"floating section header\" effect with UICollectionView. Something that\'s been easy enough in UITableView (default b

13条回答
  •  萌比男神i
    2020-11-27 10:19

    In iOS9, Apple was kind enough to add a simple property in UICollectionViewFlowLayout called sectionHeadersPinToVisibleBounds.

    With this, you can make the headers float like that in table views.

    let layout = UICollectionViewFlowLayout()
    layout.sectionHeadersPinToVisibleBounds = true
    layout.minimumInteritemSpacing = 1
    layout.minimumLineSpacing = 1
    super.init(collectionViewLayout: layout)
    

提交回复
热议问题