iOS基础

UICollectionView 各种间距设置

2018-11-14  本文已影响141人  起名好难_fz

有时候设置UICollectionView的cell间距总是不满意,慢慢才搞明白如何设置具体的间距。弄清楚下面的方法非常有用。

//定义每个Cell的大小

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

CGSize size = CGSizeMake(80,80);

return size;

//定义每个Section的四边间距

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section

{

return UIEdgeInsetsMake(15, 15, 5, 15);//分别为上、左、下、右

}

//这个是两行cell之间的间距(上下行cell的间距)

 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;

//两个cell之间的间距(同一行的cell的间距)

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;

原文:https://blog.csdn.net/u014773226/article/details/54317781

上一篇 下一篇

猜你喜欢

热点阅读