how to make dynamic width of the UICollectionViewCell

前端 未结 5 1336
粉色の甜心
粉色の甜心 2021-01-03 05:59

I want to set the width of UICollectionViewCell dynamically. I found some code in swift and I want the code in Objective-C.

let flowLayout = col         


        
5条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 06:37

    set cell's width to a percentage of the container view like:

    cell.frame = CGRectMake(x, y, self.view.frame.size.width * 20 / 100, height);
    

    or you can use CollectionView Delegates

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
        return CGSizeMake(self.view.frame.size.width*20/100, 192.f);
    }
    

提交回复
热议问题