UICollectionView layout issue on iphone 5

599 views Asked by At

I have a problem with my UICollectionView, I have 3 columns and everything works fine instead of iphone 5 and 4.

In iphone 6 my collectionview looks that (width in cell):

iphone 6 with 3 cells

iphone 6 with 2 cells

Iphone 5 with cells:

iphone 5 with 3 cells

The problem is, when in last row, I have 2 cells, and it looks like that: iphone 5 with 2 cells

The look I want to achieve:

expected iphone 5 with 2 cells

Every where I can, I set insets to (0, 0, 0, 0). I use default layout with my insets set in storyboard. So is it possible to achieve this with flow layout or I need to look into custom layout?

=== edit I create UICollectionView in storyboard and implements delegate:

- (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;
}
1

There are 1 answers

0
Wez Sie Tato On BEST ANSWER

I solved this problem by inserting an empty cell at the end of the row (only on iphone 4 & 5)

enter image description here