UICollectionView autosize height

前端 未结 9 1679
孤城傲影
孤城傲影 2020-12-04 07:02

How do I properly resize a UICollectionView so that it fully displays its contents? I have tried many things, including setting its frame, calling reloadData an

9条回答
  •  一整个雨季
    2020-12-04 07:23

    UICollectionViewFlowLayout *flowLayout;
    flowLayout = [[UICollectionViewFlowLayout alloc]init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    [flowLayout setMinimumInteritemSpacing:0.0f];
    [flowLayout setMinimumLineSpacing:0.0f];
    [self.collectionView setPagingEnabled:NO];
    [flowLayout setItemSize:CGSizeMake(322.0, 148.0)];  //important to leave no white space between the images
    [self.collectionView setCollectionViewLayout:flowLayout];
    

    I found that autolayout in the storyboard is not helping too much. A correct setting for the UICollectionViewFlowLayout for your collectionView is the real help. If you adjust item size with setItemSize, you may get the result you want.

提交回复
热议问题