UICollectionViewCell 布局

来源:互联网 发布:会声会影软件 编辑:程序博客网 时间:2024/05/24 06:00

//定义每个Item 的大小- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{    return CGSizeMake(kImageHeight, kImageHeight);}//定义每个UICollectionView 的 margin-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{    return UIEdgeInsetsMake(0, 0, 0, 0);}- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{    CGFloat width = collectionView.frame.size.width - 5*kImageHeight;    return width/5.0;}


这是我将collectionview加到tableviewcell上,

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath设定没个小单元格大小,图中就是指没个小图
<pre name="code" class="objc" style="color: rgb(0, 132, 0); font-size: 11px;">-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section设定整个collection的cell行间距(上下左右边距)

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section设定collectionview中没个小单元的间距,如图中图片与图片的间距,动态计算的话,需要这三个协议都实现



0 0
原创粉丝点击