Removing empty space, if the section header is hidden in the UICollectionView

后端 未结 5 2111
無奈伤痛
無奈伤痛 2020-12-13 08:57

I have two sections in UICollectionView. I want to show a section header in UICollectionView for only 1st section. Not in 0th section.

So I

5条回答
  •  情深已故
    2020-12-13 09:37

    At last, I found an answer for my question. I have missed something. Anyway sorry for other fellow users.

    I set the header height and width inside the below method till now as @san said.

    - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
    

    But It is not the correct method to set the frame size of supplementary views. Later I found another method inside the flowLayout, which helps me to set the header and footer sizes.

    This really works well for me:

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
    {
        if (section == 0) {
            return CGSizeZero;
        }else {
            return CGSizeMake(CGRectGetWidth(collectionView.bounds), 135);
        }
    }
    

    UPDATE: Since someone questioned about my skill in comments, attaching Apple Documentation link for returning CGSizeZero in above method.

提交回复
热议问题