Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set insets to the CollectionView programmatically in Swift

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

Thank you!

like image 571
Dmitrij Rogov Avatar asked Mar 13 '16 20:03

Dmitrij Rogov


1 Answers

Set the section inset and invalidate the layout.

let collectionViewLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout

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

collectionViewLayout?.invalidateLayout()
like image 71
Oliver Atkinson Avatar answered Nov 10 '22 09:11

Oliver Atkinson