1. 程式人生 > >collectionView代理方法快速設置cell大小上下左右間隔

collectionView代理方法快速設置cell大小上下左右間隔

同一行 height nat exp ati sin minimum size dexp

#define JianGe 25
#define GeShu 4
#define ScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define Screenheight ([UIScreen mainScreen].bounds.size.height)

//定義每個UICollectionView 的大小
- ( CGSize )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:( NSIndexPath *)indexPath {
    
return CGSizeMake((ScreenWidth - JianGe*(GeShu+1)) / GeShu, (ScreenWidth - JianGe*(GeShu+1)) / GeShu ); } //定義每個UICollectionView 的邊距 - ( UIEdgeInsets )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:( NSInteger )section {
return UIEdgeInsetsMake ( JianGe , JianGe , JianGe , JianGe ); } //設置水平間距 (同一行的cell的左右間距) -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return JianGe; } //垂直間距 (同一列cell上下間距)
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return JianGe; }

參考鏈接:collectionView代理方法快速設置cell大小上下左右間隔

collectionView代理方法快速設置cell大小上下左右間隔