UICollectionView

将 UICollectionView 的一些常用的方法和属性搞了一下
UICollectionView 和 UITableView 用法差不多也是继承UIScrollView 的

1.常用的方法:
// 根据尺寸和布局方法来创建一个 UICollectionView
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout;

// 根据代码注册 UICollectionViewCell的类型
- (void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;

// 注册 footerView 和 HeaderView 的
- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier;

// 从缓冲池中取出 Cell 和头部尾部 View
- (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath*)indexPath;
- (id)dequeueReusableSupplementaryViewOfKind:(NSString*)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath*)indexPath;

// 设置 UICollectionView 的布局方式
- (void)setCollectionViewLayout:(UICollectionViewLayout *)layout animated:(BOOL)animated;

2.属性
// cell 是否能被点击
@property (nonatomic) BOOL allowsSelection; // default is YES
// cell 是否支持多点
@property (nonatomic) BOOL allowsMultipleSelection; // default is NO

3.UICollectionViewDataSource 数据源
// 多少组
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView;
// 每组多少个 cell
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;

// 返回 cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;

// 返回 头部和尾部的 view
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

4.UICollectionViewDelegate代理方法
// 选中单元格 cell
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;


UICollectionViewFlowLayout瀑布流布局
1.属性
scrollDirection         // 滚动方向
minimumInteritemSpacing // 水平最小间距
minimumLineSpacing      // 垂直最小间距

2.UICollectionViewDelegateFlowLayout继承 UICollectionViewDelegate代理方法
// 单元格的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
}
//cell与cell之间的间隔,边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
}
//设置标题头大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
}
//设置标题尾大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值