Dynamically change cell size according to image in a UICollectionView

后端 未结 2 1004
星月不相逢
星月不相逢 2021-02-15 11:38

I am displaying dynamic images recieved from server in a horizontal collection view. When I set up the collectionview I set this:

-(void)setupCollectionView{
[se         


        
2条回答
  •  太阳男子
    2021-02-15 12:43

    However add an delegate method of UICollectionView.

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[arryOfImg objectAtIndex:indexPath.row]]];
    
        //You may want to create a divider to scale the size by the way..
        return CGSizeMake((image.frame.size.width)/4.0, (image.frame.size.height)/4.0);
    }
    

提交回复
热议问题