How to make UICollectionViewFlowLayout itemSize dynamic for screen size

前端 未结 2 2055
深忆病人
深忆病人 2021-02-19 11:02

I am working programmatically (no storyboard) and am having trouble making layout.itemSize dynamic for different screen sizes. I get this error message:

2条回答
  •  天涯浪人
    2021-02-19 11:28

    add following delegate method to your collection view

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
     {
    UIImage *image;
    long row = [indexPath row];
    
    image = [UIImage imageNamed:_carImages[row]];
    
    return image.size;
     }
    

    here a link which help you enter link description here

提交回复
热议问题