iOS:UICollectionViewCell 根据屏幕大小自动调整大小 [英] iOS: UICollectionViewCell auto adjust size according to screen size
本文介绍了iOS:UICollectionViewCell 根据屏幕大小自动调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在集合视图中创建 10 个单元格(与屏幕大小相同).当我在 iphone5s 模拟器中运行我的应用程序时,该视图正好包含 5 个单元格.但是当我切换到 iphone6p 模拟器时,视图包含超过 5 个单元格.我应该如何调整单元格大小,使屏幕中的单元格数量在不同屏幕尺寸下保持一致?
I am trying to create 10 cells in the collection view(same size as the screen). When I run my app in iphone5s simulator, the view contains exactly 5 cells. But when I switch to iphone6p simulator, the view contains more than 5 cells. How should I adjust the cell size so that the number of cells in screen are consistent across different screen sizes?
推荐答案
-(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 根据屏幕大小自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文