UICollectionView adds top margin

前端 未结 9 1673
走了就别回头了
走了就别回头了 2020-12-04 14:06

I want to put a UICollectionView control that shows thumbs horizontally (only a single line of thumbs). For some reason the UICollectionView push the thumbs 44 pixels down,

9条回答
  •  庸人自扰
    2020-12-04 14:29

    Swift 3:

    First you want to set the viewControllers automaticallyAdjustsScrollViewInsets to false:

    self.automaticallyAdjustsScrollViewInsets = false
    

    Then, you should be able to adjust the edge insets accordingly:

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        //top, left, bottom, right
        return UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
    }
    

提交回复
热议问题