How to set UICollectionViewCell Width and Height programmatically

后端 未结 20 1280
终归单人心
终归单人心 2020-12-04 08:06

I am trying to implement a CollectionView. When I am using Autolayout, my cells won\'t change the size, but their alignment.

Now I would rather want to

20条回答
  •  孤街浪徒
    2020-12-04 09:01

    This is my version, find your suitable ratio to get the cell size as per your requirement.

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
    { 
    return CGSizeMake(CGRectGetWidth(collectionView.frame)/4, CGRectGetHeight(collectionView.frame)/4); 
    } 
    

提交回复
热议问题