UICollectionView 拾遗
2017-08-21 14:47
190 查看
1.如何给collectionView添加类似于tableview的 tableHeaderView
可以先给collectionView设置内边距 即insets 然后给collectionView添加子视图,注意子视图的frame的y是负值
2.如何给collectionView添加类似于tableview的 tableFooterView
可以先给collectionView设置内边距 即insets 然后给collectionView添加子视图,注意子视图的frame的y是
flowLayout.collectionViewContentSize.height
3.如何实现不同的section的head的高度不同
可以通过实现这个代理方法
UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section {
if (section ==0) {
returnCGSizeMake(0,200);
}
else {
returnCGSizeMake(0,100);
}
}
如果head还有子视图,记得在DataSource的代理方法中重置子视图的frame
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString
*)kind atIndexPath:(NSIndexPath *)indexPath {
// reusableView的宽和设置的headerReferenceSize设置的宽不相关
UICollectionReusableView *reusableView = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:headerViewIDforIndexPath:indexPath];
if (![reusableViewviewWithTag:10001]) {
UILabel *serviceCategoryLab = [[UILabelalloc]initWithFrame:reusableView.bounds];
serviceCategoryLab.backgroundColor = [UIColoryellowColor];
serviceCategoryLab.tag =10001;
[reusableView addSubview:serviceCategoryLab];
}
UILabel *serviceCategoryLab = (UILabel *)[reusableViewviewWithTag:10001];
serviceCategoryLab.frame = reusableView.bounds;
serviceCategoryLab.text =@"测试头分区";
return reusableView;
}
可以先给collectionView设置内边距 即insets 然后给collectionView添加子视图,注意子视图的frame的y是负值
2.如何给collectionView添加类似于tableview的 tableFooterView
可以先给collectionView设置内边距 即insets 然后给collectionView添加子视图,注意子视图的frame的y是
flowLayout.collectionViewContentSize.height
3.如何实现不同的section的head的高度不同
可以通过实现这个代理方法
UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section {
if (section ==0) {
returnCGSizeMake(0,200);
}
else {
returnCGSizeMake(0,100);
}
}
如果head还有子视图,记得在DataSource的代理方法中重置子视图的frame
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString
*)kind atIndexPath:(NSIndexPath *)indexPath {
// reusableView的宽和设置的headerReferenceSize设置的宽不相关
UICollectionReusableView *reusableView = [collectionViewdequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:headerViewIDforIndexPath:indexPath];
if (![reusableViewviewWithTag:10001]) {
UILabel *serviceCategoryLab = [[UILabelalloc]initWithFrame:reusableView.bounds];
serviceCategoryLab.backgroundColor = [UIColoryellowColor];
serviceCategoryLab.tag =10001;
[reusableView addSubview:serviceCategoryLab];
}
UILabel *serviceCategoryLab = (UILabel *)[reusableViewviewWithTag:10001];
serviceCategoryLab.frame = reusableView.bounds;
serviceCategoryLab.text =@"测试头分区";
return reusableView;
}
相关文章推荐
- 《未来之路》拾遗
- Asp.net Ajax1.0学习拾遗
- PHP拾遗2
- Cross-Page Postback 拾遗
- django拾遗之signal
- VC的CListCtrl控件拾遗
- 第03篇:C#星夜拾遗之语法基础
- Unix命令 拾遗
- javascript基础拾遗——词法作用域
- ssh项目开发中细节拾遗6.29-6.30
- linux 拾遗
- Windows Phone 拾遗
- vim命令拾遗[zz]
- Android-x86 调试程序拾遗
- Objective-C 拾遗
- JavaSE 拾遗(2)——JavaSE 面向对象程序设计语言基础(2)...变量
- Struts2标签拾遗
- C#基础原理拾遗——面试都爱问的委托和事件(纠正)
- 拾遗:Linux 用户及权限管理基础
- Hadoop: the definitive guide 第三版 拾遗 第十二章 之Hive分区表、桶