16

I have ViewController with the CollectionView in it. I want to change CollectionView insets by pressing button. What code I should implement?

Thank you!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Dmitrij Rogov
  • 183
  • 1
  • 2
  • 9

1 Answers1

36

Set the section inset and invalidate the layout.

let collectionViewLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout

collectionViewLayout?.sectionInset = ... // some UIEdgeInset

collectionViewLayout?.invalidateLayout()
Oliver Atkinson
  • 7,970
  • 32
  • 43