在项目中,我是自定义的headerView,创建了一个分类,继承自 UICollectionReusableView 。 如 @interface HeaderCRView : UICollectionReusableView
在.m文件中重写headerCRView的初始化方法,添加对应的控件; 然后在Vc里面通过registerClass把该类注册进去 如 [self.collectionView registerClass:[HeaderCRView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kheaderIdentifier]; 当然这个设置不能忘记:(备注:这个方法在最新的xCode中看不到,是隐藏的方法,只需要复制使用) -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{ CGSize size={320,45}; return size; }