UI基础:UICollectionView
2015-08-22 17:37
399 查看
UITableView 和 UICollectionView的设计思路:
1.UITableView 的布局由TableView和UItableViewDelegate完成.
2.UICollectionView布局样式由UICollectionViewFlowLayout和UICollectionViewDelegate完成.
数据源:
1.UITableView由UITableViewDataSource提供.
2.UICollectionView由UICollectionViewDataSource提供.
布局样式:
1.UITableView是多列单行.
2.UICollectionView是多行多列.
1.UITableViewCell上自带imageView.textLable.detailLabel.
2.UICollectionCell自带了contentView,contentView.
1.UItableViewCell创建时直接使用,后来使用了重用机制+注册.
2.UICollectionViewCell只有注册.
共同点:二者都是继承于UIScrollView,够可以滚.
代理UICollectionViewDataSource的协议中必须实现的两个方法:
1.UITableView 的布局由TableView和UItableViewDelegate完成.
2.UICollectionView布局样式由UICollectionViewFlowLayout和UICollectionViewDelegate完成.
数据源:
1.UITableView由UITableViewDataSource提供.
2.UICollectionView由UICollectionViewDataSource提供.
布局样式:
1.UITableView是多列单行.
2.UICollectionView是多行多列.
1.UITableViewCell上自带imageView.textLable.detailLabel.
2.UICollectionCell自带了contentView,contentView.
1.UItableViewCell创建时直接使用,后来使用了重用机制+注册.
2.UICollectionViewCell只有注册.
共同点:二者都是继承于UIScrollView,够可以滚.
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];//初始化一个布局类CollectionView layout.itemSize = CGSizeMake(150, 200); //设置每个Item大小 layout.sectionInset = UIEdgeInsetsMake(20, 5, 10, 5); //设置每个item之间的间隙,上右下左 layout.minimumLineSpacing = 15; //最小行间距 UICollectionView * collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:layout];//初始化一个CollectionView,并使用layout初始化 collectionView.delegate = self;//设置代理和dataSource collectionView.dataSource = self; [self.view addSubview:collectionView]; [collectionView release]; [layout release]; // 设置页眉的大小 layout.headerReferenceSize = CGSizeMake(320,40); layout.footerReferenceSize = CGSizeMake(320, 20); // 注册 Cell [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCollectionCell]; // 注册 页眉(header) [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kElementHeadView]; // 页脚(footer) [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:kElementFootView];
代理UICollectionViewDataSource的协议中必须实现的两个方法:
// 返回每个分区里 item 的个数 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { } //重用 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ }
// 点击 item 触发的方法 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { } // 返回每个 item 的大小 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { } // 返回每个分区的缩进量 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { } // 返回行间距 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { } // 返回 item 的间距 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { } // 返回页眉的 size - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { } // 返回页脚的 size - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section { }
相关文章推荐
- hdu 2818 Building Block(加权并查集)2009 Multi-University Training Contest 1
- LeetCode-N-Queens
- VS2012加载DLL编译出现试图加载格式不正确的程序; 以及运行出现Mixed mode assembly is built against version 'v2.0.50727' of the
- 动态限制UITextField或UITextView用户输入中英文混编字数统计
- uint16,uint32是什么?
- uint16,uint32是什么?
- GDI+ 使用指南(basic guiding of GDI plus )
- 如何在UEFI+GPT下使用rEFind实现Win10 + Kali2.0 双引导!
- hdu5400 Arithmetic Sequence
- UIButton及UITextfield
- UI-封装
- UIViewController
- UI-UIImageView
- HTML初体验之1——关于HBuilder文件放置
- UI -视图控制器UIViewController
- UIView及其子类
- iOS 笔记三: UITextView和视图控制器生命周期(View Controller LifeCycle)
- The one who can give anything you want is only yourself. The rating is the only you should pursue.
- UI - 组合控件LTView(UILabel + UITextField)
- UITextField功能方法详解