UICollectionView Layout Issue

前端 未结 15 1742
天涯浪人
天涯浪人 2020-12-24 00:17

I am using UICollectionView using the flow layout. I have made a custom UICollectionViewCell for the same. But on running the project the console k

15条回答
  •  春和景丽
    2020-12-24 00:53

    I have same issue

    the behavior of the UICollectionViewFlowLayout is not defined because: the item height must be less than the height of the UICollectionView minus the section insets top and bottom values.

    I solved this issue by checking the values in section Insets.And for fix cell size I have used below code.

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    CGFloat scale = [UIScreen mainScreen].scale;
    result = CGSizeMake(result.width * scale, result.height * scale);
    CGFloat cellWidth =  [[UIScreen mainScreen] bounds].size.width - 20;
    CGFloat cellHeight = [[UIScreen mainScreen] bounds].size.height - 120;
    
    return CGSizeMake(cellWidth, cellHeight);
    
    
    }
    

提交回复
热议问题