Ios 如何设置UICollectionViewCell大小?

Ios 如何设置UICollectionViewCell大小?,ios,swift,uicollectionview,uicollectionviewcell,Ios,Swift,Uicollectionview,Uicollectionviewcell,我想将collectionViewCell大小从更改为 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 为此,我愿意: (collectionView.collectionViewLayout as! UICollectionViewFlowLayout).itemSize = 100

我想将collectionViewCell大小从更改为

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
为此,我愿意:

(collectionView.collectionViewLayout as! UICollectionViewFlowLayout).itemSize = 1000
但它根本不会改变大小。此外,我还有下一个功能:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    var newSize: CGSize?

    let width = CGRectGetWidth(collectionView.frame)
    newSize = CGSize(width: width, height: width + 100)

    return newSize!
}

那么,如何从
单元格中覆盖它呢?

您需要在项目中包括
UICollectionViewDelegateFlowLayout
,然后实现
-(CGSize)collectionView:(UICollectionView*)collectionView布局:(UICollectionViewLayout*)collectionViewLayout SizeFormitedXPath:(NSIndexPath*))索引
方法设置集合视图单元格的大小。

设置集合视图单元格大小时,只需重写集合视图委托方法
sizeForItemAtIndexPath
。@RichardG如何从
CellForItemIndePath
执行此操作?当我将
override
添加到
sizeForItemAtIndexPath
时,会出现一个错误
方法不重写任何方法