[英]setting UICollectionViewCell to fit CollectionView
我正在尝试在收藏夹视图中显示图片,一次显示1张图片,并允许它们水平滚动。
所以我希望单元格适合集合视图的大小,也许有些余量。
我尝试通过将单元格框架设置为与集合视图的框架相同的方式来完成此操作
CGRect containerFrame = self.photoCollectionView.frame;
cell.frame = CGRectMake(containerFrame.origin.x, containerFrame.origin.y, containerFrame.size.width, containerFrame.size.height);
但细胞只是一起消失了 有标准的方法吗?
看看UICollectionViewFlowLayout类参考 。 您应该使用UICollectionViewDelegateFlowLayout
。
实现此方法以更改单元格的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
并更改单元格之间的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.