UICollectionView添加SectionHeader
作者:
songjk | 来源:发表于
2020-09-01 09:58 被阅读0次注册view
[_collView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView"];
代理方法
//组头高度
-(CGSize )collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
return CGsizeMake(SCREEN_WIDTH, 100);
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView" forIndexPath:indexPath];
UILabel *label = [[UILabel alloc]init];
label.text = @"hello";
for (UIView *view in header.subviews) {
[view removeFromSuperview];
}
[header addSubview:label];
return header;
} else {
return nil;
}
}
本文标题:UICollectionView添加SectionHeader
本文链接:https://www.haomeiwen.com/subject/rdwmsktx.html
网友评论