iOS-collectionView,简单布局简单使用

简单的布局,简单的使用,效果如下

首先一定要确定每个cell的大小,以及cell之间的间距、边距之间的距离和

#pragma mark --UICollectionViewDelegateFlowLayout

//定义每个Item 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //KDECEIVE_WIDTH为[UIScreen mainScreen].bounds.size.width,12为边距、间距的和,colletionCell的列数
    CGFloat height= (KDECEIVE_WIDTH-12)/colletionCell;
    return  CGSizeMake(height, height);  //设置cell宽高
}

//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(4, 4, 4, 4);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 4;
}

// 两行之间的最小间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 4;
}

 

posted @ 2016-08-30 16:43  tomandhua  阅读(397)  评论(0编辑  收藏  举报