调整 Collection 屏幕尺寸的视图单元格

Adjusting Collection View Cells for Screen Size

这是我用来设置 collection 视图的代码。

- (void) setUpCollectionView {

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];

[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

[flowLayout setMinimumInteritemSpacing:0.0f];

[flowLayout setMinimumLineSpacing:0.0f];

[flowLayout setItemSize:CGSizeMake(320, 566)];

[self.collectionView setPagingEnabled:YES];

[self.collectionView setCollectionViewLayout:flowLayout];

}

我正在将流式布局的项目大小设置为设定大小。我想知道我可以根据用户使用的当前屏幕尺寸调整此尺寸。谢谢

如果您的集合视图设置了约束以使其适应屏幕大小,则将您的单元格大小设置为与集合视图相同。

[flowLayout setItemSize:CGSizeMake(self.collectionView.frame.size.width, self.collectionView.frame.size.height)];