我想改变 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!
}
那么,如何从 cellForItemAtIndexPath
中覆盖它?
最佳答案
你需要在你的项目中包含UICollectionViewDelegateFlowLayout
然后实现- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
设置 Collection View 单元格大小的方法。
关于ios - 如何设置 UICollectionViewCell 大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36549322/