Search code examples
iosswiftcellcollectionview

How to programmatically change the UICollectionView Cell location


  1. How to change spacing between the navigation bar and the first collectionViewCell?

enter image description here

  1. I want to be aligned in the middle. In this case, the only way to calculate the screen size?

enter image description here


Solution

    1. If you want to add space at the top of your collection view you can use contentInset. There are probably other ways to meet your requirement but this is the easiest way I can think of.

      collectionView.contentInset = UIEdgeInsets(top: 100, left: 0, bottom: 0, right: 0)

    2. I don't understand what you are trying to do. Can you explain more?