如何根据设备屏幕大小调整集合视图单元格的大小? [英] How to resize the collection view cells according to device screen size?
本文介绍了如何根据设备屏幕大小调整集合视图单元格的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到细胞总是遵循尺寸检查器中的定义。即使我已经应用了UICollectionViewDelegateFlowLayout。
I noticed that the cells would always follow the definition in size inspector. Even if I have already applied UICollectionViewDelegateFlowLayout.
< a href =https://i.stack.imgur.com/KvIMK.png =noreferrer>
这就是它的外观。但是我希望细胞看起来更像是在较小的iphone屏幕上。
So that's how it looks. But I want the cells to rather look like how it was on a smaller iphone screen.
推荐答案
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = self.view.frame.size.height;
CGFloat width = self.view.frame.size.width;
// in case you you want the cell to be 40% of your controllers view
return CGSizeMake(width * 0.4, height * 0.4);
}
这篇关于如何根据设备屏幕大小调整集合视图单元格的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文