xcode Swift 3 操纵 UICollectionViewCell 大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40271369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:30:10  来源:igfitidea点击:

Swift 3 manipulating UICollectionViewCell size?

iosswiftxcodeuicollectionviewswift3

提问by Recusiwe

I'm struggling with manipulating my UICollectionViewCell sizes, since it seem the function is deprecated, same goes for spacing. I've tried with this one:

我正在努力操纵我的 UICollectionViewCell 大小,因为该功能似乎已被弃用,间距也是如此。我试过这个:

func collectionView(collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSize(width: 150, height: 150)
    }

Which function am I supposed to use in Swift 3?

我应该在 Swift 3 中使用哪个函数?

回答by fzh

you can try this code in swift3

您可以在 swift3 中尝试此代码

override var collectionViewContentSize: CGSize {
    return CGSize(width: 150, height: 150)
}

回答by serhat sezer

You can use below delegate method.

您可以使用以下委托方法。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        return CGSize(width: 100, height: 100)
    }