UICollectionView display 3 items per row

后端 未结 7 591
离开以前
离开以前 2020-12-16 03:30

I have a UICollectionView created from storyboard,

I want to have 3 items per row in the view. I managed to do that using the following:

    - (CGSiz         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 04:16

    here i did it , i implemented UICollectionViewDelegateFlowLayout on UICollectionView add following method . it work , use it .

    - (CGSize)collectionView:(UICollectionView *)collectionView
                      layout:(UICollectionViewLayout *)collectionViewLayout
      sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        CGFloat screenWidth = screenRect.size.width;
        float cellWidth = screenWidth / 3.0; //Replace the divisor with the column count requirement. Make sure to have it in float.
        CGSize size = CGSizeMake(cellWidth, cellWidth);
    
        return size;
    }
    

    this method work as screen size width divided by 3 .

提交回复
热议问题