iOS - UICollectionView最基本的介绍

2016-11-12  本文已影响0人  小_黑_屋

人一切的痛苦,本质上都是对自己的无能的愤怒。


目录

1.UICollectionView的基本概念
2.UICollectionViewFlowLayout的基本属性
3.UICollectionView的代理方法


UICollectionView的基本概念


UICollectionViewFlowLayout的基本属性

特别注意:这里的两个属性是和你的滑动方向有关的,不是和网上说的minimumLineSpacing是行距,minimumInteritemSpacing是列距,这种是不对的。和滑动方向有关!!!


UICollectionView代理方法

//返回多少个分组
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//每组有多少个cell
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 40;
}

//每个位置显示哪个cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor yellowColor];
    return cell;
}

//点击cell之后执行的操作
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

//返回YES则可以移动cell的位置 
//这个需要给cell添加手势,然后再在移动中交换cell位置 (下期会有介绍详细使用 及demo)
- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

以上是UICollectionView的一个最基本的使用的介绍,下期会对这些做个小例子,然后如果文中有任何错误,欢迎指正。

上一篇 下一篇

猜你喜欢

热点阅读