您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页关于UICollectionView Section头尾视图

关于UICollectionView Section头尾视图

来源:伴沃教育

用 xib 生成 UICollectionViewSection 头尾视图

首先注册一个 UICollectionReusableView 类 ps:不注册会crash

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

记住在XIB中 设置高度  以及开启头尾视图设置

头尾视图 宽高 宽度不设置默认于视图一样

再这个方法里生成头视图

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

{

UICollectionReusableView *reusableview = nil;

判断为头视图 或 尾视图 

UICollectionElementKindSectionFooter 

UICollectionElementKindSectionHeader

if (kind == UICollectionElementKindSectionHeader)

从队列取头视图

UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];

reusableview = headerView;

}

reusable view 其实就是一个view 

reusableview.backgroundColor = [UIColor redColor];

return reusableview;

}

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务