首页 > 移动平台 > 详细

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

时间:2016-08-30 17:24:21      阅读:282      评论:0      收藏:0      [点我收藏+]

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

技术分享

首先一定要确定每个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;
}

 

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

原文:http://www.cnblogs.com/tomandhua/p/5822616.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!