OGeek|极客世界-中国程序员成长平台

标题: ios - 如何使 UICollectionViewCell 高度填充框架的所有大小? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:13
标题: ios - 如何使 UICollectionViewCell 高度填充框架的所有大小?

我正在尝试使用 CollectionViewCell 来填充 CollectionView 的所有框架,但是我无法做到这一点,相反,它看起来像这样: How it currently looks

如您所见,uicollectionview 框架的顶部和底部有一个空间,不应该出现。

配置如下:

//////////////////////////////
    //     Collection View      //
    //////////////////////////////
    self.collectionView.delegate = self
    self.collectionView.dataSource = self

    self.automaticallyAdjustsScrollViewInsets = false

    let screenWidth = UIScreen.mainScreen().bounds.width
    let viewHeight = viewContainer.frame.height

    let collectionViewFlowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
    collectionViewFlowLayout.itemSize = CGSizeMake(screenWidth, viewHeight)
    collectionViewFlowLayout.minimumInteritemSpacing = 0.0
    collectionViewFlowLayout.minimumLineSpacing = 0.0
    collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)

如何删除这些不需要的空格?



Best Answer-推荐答案


重写 UICollectionViewFlowLayout 委托(delegate)方法并返回大小等于 collectionview 大小:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
       return collectionView.frame.size;
}

关于ios - 如何使 UICollectionViewCell 高度填充框架的所有大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34184795/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4