我的UICollectionView有问题,我有3列,一切正常,而不是iphone 5和4。
在iphone 6中,我的collectionview看起来(单元格中的宽度):
Iphone 5 with cells:
问题是,在最后一行,我有2个单元格,看起来像这样:
我想要实现的目标:
我可以在任何地方设置插入(0,0,0,0)。我使用默认布局和我在故事板中设置的插图。那么有可能通过流程布局来实现这一点,或者我需要研究自定义布局?
===编辑 我在storyboard中创建了UICollectionView并实现了委托:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
float width = self.frame.size.width / 3.0f;
float height = floorf(width + 118);
if(SMALLER_THAN_6){
width = floorf(width);
if([indexPath row] % 3 < 2){
++width;
}
}
return CGSizeMake(width, height);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 0.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 0.0;
}
答案 0 :(得分:0)
我通过在行的末尾插入一个空单元格(仅在iphone 4&amp; 5上)解决了这个问题