UICollectionView分组-组头处理

时间:2022-03-16 15:12:19

UICollectionView分组


设置组头

1先设置组头高度

    

collectionViewLayout.headerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 40);


2.注册组头

    

UINib *headerNib = [UINib nibWithNibName:@"NMDDiyShapeListHeaderView" bundle:nil];
    [_diyShapListCollectionView registerNib:headerNib forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"NMDDiyShapeListHeaderView"];

3.自定义组头  


xib中有UICollectionReusableView

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    NMDToeCapTypeListInfo *info = _DiyShapeList[indexPath.section];
    NMDDiyShapeListHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"NMDDiyShapeListHeaderView" forIndexPath:indexPath];
    headerView.title = info.toeCapTypeName;
    return headerView;
}