使用 collectionView 实现表头,区头,区尾
UICollectionView 的使用是跟表的使用是一样,瀑布流的布局会比表的效果更好,这里说一下 collectionView 设置表头, 区头,区尾
设置表头可以约束 collectionView 居上的距离
其中区头,区尾 是继承 UICollectionReusableView
//
// HomePageViewController.m
// MainStoryboard
//
// Created by mac on 16/4/21.
// Copyright © 2016年 mac. All rights reserved.
// #import "HomePageViewController.h"
#import "ZMZScrollView.h"
#import "ZkCollectionViewCell.h"
#import "MyHeaderViewView.h" #define kScreenWidth [UIScreen mainScreen].bounds.size.width #define KScreenHeight [UIScreen mainScreen].bounds.size.height #define ARMCOLOR [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1] @interface HomePageViewController ()<UICollectionViewDataSource,UICollectionViewDelegate> @property (nonatomic, strong) UICollectionView* collectionView ; @end //设置标识
static NSString * indentify = @"indentify"; @implementation HomePageViewController - (void)viewDidLoad { [super viewDidLoad]; /**
* 先创建 collectionView 在创建下面的 scrollView
*/ [self waterfall]; [self createScrollView]; }
#pragma mark 轮播广告
- (void)createScrollView
{
ZMZScrollView *ZScroller = [[ZMZScrollView alloc]initWithFrame:CGRectMake(, -, kScreenWidth, )]; ZScroller.imageNameArray = @[@"http://upload.chadaodian.com/mobile/special/s0/s0_05134290739539518.jpg",@"http://upload.chadaodian.com/mobile/special/s0/s0_05134291123904050.jpg",@"http://upload.chadaodian.com/mobile/special/s0/s0_05134291206563185.jpg"]; ZScroller.backgroundColor = [UIColor redColor]; [self.collectionView addSubview:ZScroller]; }
-(void)waterfall{ UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumInteritemSpacing = 1.0f; [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kScreenWidth, KScreenHeight-64.0f) collectionViewLayout:flowLayout]; self.collectionView.backgroundColor = [UIColor colorWithRed: / 255.0f green: / 255.0f blue: / 255.0f alpha:1.0f]; self.collectionView.contentInset = UIEdgeInsetsMake(200.0f, 0.0f, 0.0f, 0.0f); self.collectionView.delegate=self;
self.collectionView.dataSource = self; [self.view addSubview:self.collectionView]; #pragma mark -- 头部大小设置
[flowLayout setHeaderReferenceSize:CGSizeMake(kScreenWidth, 40.0f)];
/**
* 这里还可以设置区尾的大小
*/ #pragma mark -- 注册单元格
[self.collectionView registerNib:[UINib nibWithNibName:@"ZkCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:indentify]; #pragma mark -- 注册头部视图
[self.collectionView registerClass:[MyHeaderViewView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"]; /**
* 这里注册区尾
*
*/
} //设置头部内容
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableView = nil; if (kind == UICollectionElementKindSectionHeader) {
//定制头部视图的内容
MyHeaderViewView * headerV =(MyHeaderViewView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath]; headerV.titleLab.text = [NSString stringWithFormat:@"section %ld's header",(long)indexPath.section];; reusableView = headerV;
}
/**
* 在这里设置区尾 UICollectionElementKindSectionFooter
*/ return reusableView;
} #pragma mark - UICollectionViewDelegateWaterfallLayout //返回 indexPath 处的 item 的大小。
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{ return CGSizeMake(170.0f, 220.0f); }
//设定全局的行间距,如果想要设定指定区内Cell的最小行距,
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{ return 15.0f;
} //设定collectionView(指定区)的边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ return UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
} #pragma mark - UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return ;
} - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return ;
} - (UICollectionViewCell* )collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { ZkCollectionViewCell* cell =[collectionView dequeueReusableCellWithReuseIdentifier:indentify forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor]; cell.synopsisLabel.text=@"";
return cell;
} //点击单元格
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%ld区--%ld单元格",(long)indexPath.section,(long)indexPath.row);
} @end
使用 collectionView 实现表头,区头,区尾的更多相关文章
- TableView之表头、表尾,区头、区尾!
一.UITableView的UITableViewStyle 样式分为UITableViewStylePlain和UITableViewStyleGrouped两种: plain样式下区头和区尾是悬浮 ...
- tableView区头不显示
不知道什么原因 如果设置tableView的样式为Group 则必须写代理 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; co ...
- tableIView 区头的一点问题
要记得设置区头的高度 否则会出现第一行没区头问题
- UITableView的plain样式下,取消区头停滞效果
核心代码 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat sectionHeaderHeight = sectionH ...
- C++中栈区 堆区 常量区
原文地址:http://blog.csdn.net/xcyuzhen/article/details/4543264 C++中栈区 堆区 常量区(由一道面试题目而学习) -- : #include&l ...
- iOS之UITableView组头组尾视图/标题悬停
最近笔者在公司的iOS开发中,有一个iOS开发同事跑来问了两个问题:1.给UITableView设置了组头和组尾视图,但是一直显示不出来?2.UITableView的section的header和fo ...
- iOS程序中的内存分配 栈区堆区全局区
在计算机系统中,运行的应用程序的数据都是保存在内存中的,不同类型的数据,保存的内存区域不同.一.内存分区 栈区(stack) 由编译器自动分配并释放,存放函数的参数值,局部变量等.栈是系统数据结构,对 ...
- Android ListView相关 头和尾 headView footerView
ListView还可以添加头和尾部,而这头和尾就是View对象, 可以使用listView.addHeadView(view)方法和listView.addFootView(view)方法分别添加头和 ...
- 【京东账户】——Mysql/PHP/Ajax爬坑之页头页尾加载
一.引言 实现京东的账户项目,有一个小功能,页头页尾加载.要用到的是Apach环境,Mysql.PHP以及Ajax. 二.实现 原理: 用php文件分别写一个的页头和一个页尾,放在前后两个div里. ...
随机推荐
- Spark中的编程模型
1. Spark中的基本概念 Application:基于Spark的用户程序,包含了一个driver program和集群中多个executor. Driver Program:运行Applicat ...
- Java Client for Google Cloud Storage
关于Google Cloud Storage Google Cloud Storage有益于大文件的存储与服务(serve).此外,Cloud Storage提供了对访问控制列表(ACLs)的使用,提 ...
- linux查看端口信息以及关闭进程
lsof -i:6633 查看端口6633的使用情况 kill (+PID数值),结束进程
- pku3668 Game of Lines
http://poj.org/problem?id=3668 水题,STL #include <stdio.h> #include <set> using namespace ...
- gulp之静态资源防缓存处理
最近,因为校友网项目开始有些规模了.开始就要考虑对静态资源进行工程自动化的管理.一讲到前端的自动化工具,大家或许都会想到Grunt,Gulp,或者百度的FIS.这三个都有各自的特点,大家可以依据自己的 ...
- Laravel Controllers
Basic Controllers Instead of defining all of your route-level logic in a single routes.php file, you ...
- poj 1236 Network of Schools(连通图入度,出度为0)
http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- POJ 2186 Popular Cows(强连通分量缩点)
题目链接:http://poj.org/problem?id=2186 题目意思大概是:给定N(N<=10000)个点和M(M<=50000)条有向边,求有多少个“受欢迎的点”.所谓的“受 ...
- OOP 6大基本原则
1.开闭原则: 对扩展开发.对修改关闭. 2.里氏替换原则:子类替换父类(可以用父类对象的任何地方都可以用子类对象代替) 3.依赖倒置原则:程序要依赖于抽象接口,不要依赖于具体实现.简单的说就是要求对 ...
- C# 生成解决方案失败,点击项目重新生成报找不到命名空间
1.点击生成解决方案失败,点击项目“重新生成”找不到“XXX”命名空间. 尝试点击"重新生成解决方案"多次,然后点击项目的"重新生成"即可解决.