我有一个CollectionView,每个CollectionViewCell中都有一张图片。我想在任何给定的框架/屏幕尺寸下仅显示3个单元格。我该如何实现这个功能?我已经根据这篇文章编写了一些代码。
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let numberOfCell = 3
let cellWidth: CGFloat = [[UIScreen mainScreen].bounds].size.width/numberOfCell
return CGSizeMake(cellWidth, cellWidth)
}
但是它无法正常工作并且出现了错误。最好的方法是什么?