使用 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里. ...
随机推荐
- 从Count看Oracle执行计划的选择
一. 前言 在调查一个性能问题的时候,一个同事问道,为什么数据库有些时候这么不聪明,明明表上有索引,但是在执行一个简单的count的时候居然全表扫描了!难道不知道走索引更快么? 试图从最简单的coun ...
- scribe、chukwa、kafka、flume日志系统对比 -摘自网络
1. 背景介绍许多公司的平台每天会产生大量的日志(一般为流式数据,如,搜索引擎的pv,查询等),处理这些日志需要特定的日志系统,一般而言,这些系统需要具有以下特征:(1) 构建应用系统和分析系统的桥梁 ...
- Java NIO 缓冲区学习笔记
Buffer其实就是是一个容器对象,它包含一些要写入或者刚读出的数据.在NIO中加入Buffer对象,体现了新库与原I/O的一个重要区别.在面向流的I/O中,您将数据直接写入或者将数据直接读到Stre ...
- sizeof 字符数组
比较 #include <stdio.h> #include <string.h> int main(int argc, const char *argv[]) { char ...
- 【C++专题】static_cast, dynamic_cast, const_cast探讨
首先回顾一下C++类型转换: C++类型转换分为:隐式类型转换和显式类型转换 第1部分. 隐式类型转换 又称为“标准转换”,包括以下几种情况:1) 算术转换(Arithmetic conversion ...
- [iOS UI进阶 - 0] Quiartz2D
A.简介 1. 需要掌握的 drawRect:方法的使用 常见图形的绘制:线条.多边形.圆 绘图状态的设置:文字颜色.线宽等 图形上下文状态的保存与恢复 图形上下文栈 1.基本图形绘制* 线段(线宽. ...
- delphi 窗口最大化后控件的大小变化怎么设置
设置按钮的Anchors属性.可以通过此属性设置其边界是否随父类一起变化.默认akleft+aktop即左边界和上边界随窗口变化,也就是说如果窗口位置移动了,按钮将保持其left和top边界与窗口的距 ...
- javascript中sleep等待实现
function sleep(milliSeconds) { var startTime = new Date().getTime(); while (new Date().getTime() < ...
- Java常用类(String、StringBuffer、Math、Arrays)
1.String 操作对象时会重新分配堆内存,栈内存的引用会重新指向新的堆内存 2.StringBuffer(字符串缓存区) 操作的对象一直都是一个 3.Math Math.max(xx,xx); M ...
- easyUI之tree
转自:http://www.cnblogs.com/CoreCaiNiao/archive/2010/08/20/1804387.html http://blog.csdn.net/l27775918 ...