关于collectionView 的头视图

1. 头视图大小

 layout.headerReferenceSize = CGSizeMake(375, 200);

// 注册头视图

    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerReuse"];

    

// 设置表头和区域内容

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

{

    

 UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"headerReuse" forIndexPath:indexPath];

  

    headerView.backgroundColor = [UIColor cyanColor];

    headerView.userInteractionEnabled = YES;

  return headerView;

}

原文地址:https://www.cnblogs.com/fan-cong/p/4878419.html