Ios 如何设置UICollectionViewCell大小?
我想将collectionViewCell大小从更改为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
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
时,会出现一个错误方法不重写任何方法