今天想實現一個collectionView的效果: 一行放兩個cell 保證cell之間的距離等於左邊cell離最左邊的距離 右邊的cell到最右邊的距離函數
解決方法以下:io
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {方法
UIEdgeInsets top = {18,10,20,10};layout
return top;top
}view
這個函數是保證collectionview的一個整section離上邊 左邊 下邊 右邊的距離 上個函數說明掙個section離上左下右分別爲18,10,20,10vi
因此咱們只需設定cell的大小 cell之間的間距天然就算出來了co