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
Swift 3 manipulating UICollectionViewCell size?
提问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)
}