我正在尝试在 Collection View 中创建 10 个单元格(与屏幕大小相同)。当我在 iphone5s 模拟器中运行我的应用程序时,该 View 恰好包含 5 个单元格。但是当我切换到 iphone6p 模拟器时, View 包含超过 5 个单元格。我应该如何调整单元格大小,使屏幕中的单元格数量在不同屏幕尺寸下保持一致?
最佳答案
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
int numberOfCellInRow = 3;
CGFloat cellWidth = [[UIScreen mainScreen] bounds].size.width/numberOfCellInRow;
return CGSizeMake(cellWidth, cellWidth);
}
关于iOS:UICollectionViewCell 根据屏幕大小自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30075408/