我正在尝试在集合视图中创建10个单元格(与屏幕大小相同)。当我在iPhone5s模拟器上运行我的应用程序时,视图恰好包含5个单元格。但是,当我切换到iPhone6p模拟器时,视图包含超过5个单元格。我应该如何调整单元格大小,以使不同屏幕尺寸下屏幕上的单元格数量保持一致?
我正在尝试在集合视图中创建10个单元格(与屏幕大小相同)。当我在iPhone5s模拟器上运行我的应用程序时,视图恰好包含5个单元格。但是,当我切换到iPhone6p模拟器时,视图包含超过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);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake([(NSString*)[[tagArray objectAtIndex:indexPath.row] objectForKey:@"tag"] sizeWithAttributes:NULL].width+10, 40);
}