怎样在UICollectionView中tableview添加headerr和footer

IOS-UICollectionView的基本使用以及添加headerView
IOS-UICollectionView的基本使用以及添加headerView
UICollectionView 说白了就是照片墙
在展示类的App中也很常见,比如:瀑布流。
下面说一下如何简单的使用 和如何添加headerView 让他也拥有类似于tableview的headerView的效果
UIKIT_EXTERN
NSString *const UICollectionElementKindSectionH &//定义好Identifier&
NSString *const HeaderIdentifier =
@&HeaderIdentifier&;
&UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout
init]; &//此处自动布局,我没有写任何东西 布局样式都在cell中
& & _collectionView=[[UICollectionView
alloc] initWithFrame:CGRectMake(0,
0, self.view.width,
self.view.height-70)
collectionViewLayout:layout];
& & self.collectionView.dataSource =
& & self.collectionView.delegate =
& & self.collectionView.showsVerticalScrollIndicator =
&& &//此处需要注册才可以使用 &
& & [self.collectionView
registerClass:[DiaperColectionCell
class] forCellWithReuseIdentifier:BrankViewCellIdentifier];&
& & [self.collectionView
registerClass:[MYBrandHeaderView
class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:HeaderIdentifier];
& & [self.view&addSubview:self.collectionView];
下面执行代理方法 跟tableview 一样的
#pragma mark -
#pragma mark collectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
& & //section数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
//数据数量
//设置元素大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout
*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return&(返回一个Item的 宽高)
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath
*)indexPath
//此处就是自定义好的cell
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath
*)indexPath
//UICollectionView被选中时调用的方法
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString
*)kind atIndexPath:(NSIndexPath *)indexPath
MYBrandHeaderView *headReusableV
//此处是headerView
& & if (kind ==
UICollectionElementKindSectionHeader) {
& & & & headReusableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:HeaderIdentifier
forIndexPath:indexPath];
& & & & headReusableView.frame =
CGRectZero;
& & & & headReusableView.delegate =
& & & & headReusableView.modeNumber =
& & & & [((MYBrandHeaderView *)headReusableView)
setData:self.headerDict];
return headReusableV
//执行的&headerView 代理 &返回 headerView 的高度
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section
CGFloat height = [self.topView
getHeight];
return CGSizeMake(320, height);
感谢关注 Ithao123精品文库频道,是专门为互联网人打造的学习交流平台,全面满足互联网人工作与学习需求,更多互联网资讯尽在 IThao123!
Laravel是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。
Hadoop是一个由Apache基金会所开发的分布式系统基础架构。
用户可以在不了解分布式底层细节的情况下,开发分布式程序。充分利用集群的威力进行高速运算和存储。
Hadoop实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上;而且它提供高吞吐量(high throughput)来访问应用程序的数据,适合那些有着超大数据集(large data set)的应用程序。HDFS放宽了(relax)POSIX的要求,可以以流的形式访问(streaming access)文件系统中的数据。
Hadoop的框架最核心的设计就是:HDFS和MapReduce。HDFS为海量的数据提供了存储,则MapReduce为海量的数据提供了计算。
产品设计是互联网产品经理的核心能力,一个好的产品经理一定在产品设计方面有扎实的功底,本专题将从互联网产品设计的几个方面谈谈产品设计
随着国内互联网的发展,产品经理岗位需求大幅增加,在国内,从事产品工作的大部分岗位为产品经理,其实现实中,很多从事产品工作的岗位是不能称为产品经理,主要原因是对产品经理的职责不明确,那产品经理的职责有哪些,本专题将详细介绍产品经理的主要职责
IThao123周刊&&国之画&&&& &&
版权所有 京ICP备号-2
迷上了代码!

我要回帖

更多关于 uicollection header 的文章

 

随机推荐