UI整理-----part5--UICollectionView
2016-02-21 10:38
369 查看
(1)可以理解成多列的UITableView(这是UICollectionView的最简单的形式)
(2)实现一个UICollectionView和实现一个UITableView基本没什么大区别,它们同样都是由dataSource和delegate设计模式的:dataSource为View提供数据源,delegate提供一些样式的小细节以及用户交互响应
(3)保证CollectionView正常工作的三个方法:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView section的数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 某个section里有多少item
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 对于某个位置应该显示什么样的cell
(4)UICollectionViewCell的布局是由UICollectionViewLayout类的子类 UICollectionViewFlowLayout 决定的:
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(100, 100);
layout.minimumInteritemSpacing = 20; //设置单元格水平间隔,默认为10
layout.minimumLineSpacing = 20; //设置行间距为20
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10); //设置与边框距离
layout.scrollDirection = UICollectionViewScrollDirectionVertical; //设置滚动方向
layout.headerReferenceSize = CGSizeMake(0, 200); //设置头部视图大小只需要设置height
}
(5)在创建完布局类之后,需要实现实例化一个UICollectionView
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
(6)通过注册的方式创建单元格头视图[collectionViewregisterClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"]; 其中:UICollectionReusableView——collectionView共用的类 UICollectionElementKindSectionHeader——注册头视图的类型
(7)触摸事件:- (void)collectionView:(UICollectionView *)collectionViewdidSelectItemAtIndexPath:(NSIndexPath *)indexPath
(2)实现一个UICollectionView和实现一个UITableView基本没什么大区别,它们同样都是由dataSource和delegate设计模式的:dataSource为View提供数据源,delegate提供一些样式的小细节以及用户交互响应
(3)保证CollectionView正常工作的三个方法:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView section的数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 某个section里有多少item
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 对于某个位置应该显示什么样的cell
(4)UICollectionViewCell的布局是由UICollectionViewLayout类的子类 UICollectionViewFlowLayout 决定的:
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(100, 100);
layout.minimumInteritemSpacing = 20; //设置单元格水平间隔,默认为10
layout.minimumLineSpacing = 20; //设置行间距为20
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10); //设置与边框距离
layout.scrollDirection = UICollectionViewScrollDirectionVertical; //设置滚动方向
layout.headerReferenceSize = CGSizeMake(0, 200); //设置头部视图大小只需要设置height
}
(5)在创建完布局类之后,需要实现实例化一个UICollectionView
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
(6)通过注册的方式创建单元格头视图[collectionViewregisterClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"]; 其中:UICollectionReusableView——collectionView共用的类 UICollectionElementKindSectionHeader——注册头视图的类型
(7)触摸事件:- (void)collectionView:(UICollectionView *)collectionViewdidSelectItemAtIndexPath:(NSIndexPath *)indexPath
相关文章推荐
- 用UIInterpolatingMotionEffect产生透视效果
- ios-基础用法之【3】-import和inclue的区别
- android进行异步更新UI的四种方式(转载)
- UI_拖动View
- LeetCode Closest Binary Search Tree Value II
- 【POJ】[1679]The Unique MST
- LeetCode Closest Binary Search Tree Value
- UICollectionView自定义Layout之蜂窝布局
- reveal UI 分析工具简单使用 内附1.5.1破解版下载地址
- We Recommend a Singular Value Decomposition
- 【hdu1159】common subsequence —— 二维dp
- EasyUI闪屏EasyUI页面加载提示(原理+代码+效果图)
- String、StringBuffer与StringBuilder之间区别
- POJ 2533 —— Longest Ordered Subsequence 最长上升子序列裸题
- java中continue配合标签进行继续循环
- Handler、Looper和MessageQueue
- 为什么在jsp中写${pageContext.request.contextPath }失效了
- [置顶] NGUI另一种按钮事件触发的方法
- 1007. Maximum Subsequence Sum (25)
- Android Wear 进阶 - 3.1 Creating Custom UIs for Wear Devices-Defining Layouts 创建自定义的手表设备UIs-定义布局