2016-06-07 96 views
0

在我的應用程序中,我使用的是使用UICollectionView。我想在UICollectionViewCell之間設置修復空間。所以我該怎麼做?如何保持uicollectionview單元格之間的間距

這裏是我的代碼:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { 
    return 20 

} 

通過這條線,我可以設置單元格之間的空間?

這是我的截圖請看看這個。讓我知道我可以設置固定的距離在兩個橫向或縱向模式

enter image description here enter image description here

+1

[UICollectionView中的單元格間距]的可能重複(http://stackoverflow.com/questions/17229350/cell-spacing-in-uicollectionview) –

回答

1

也許,你需要執行如下方法。

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

您可以通過故事板敏調整UICollectionCell之間的間距。間距 UICollectionView的屬性。

enter image description here

在這裏,可以設置電池和線路最小間距值。

希望它能幫助你。

0

大小檢查如果你想在細胞之間exact間距你需要計算規模爲細胞,將最適合允許管理間距在考慮sectionInsets和CollectionView bounds時,您需要的間距不需要包裝。例如。

let desiredSpacing: CGFloat = 20.0 

if let layout = self.collectionView?.collectionViewLayout as? UICollectionViewFlowLayout { 
    layout.minimumLineSpacing = desiredSpacing 
    let totalCellsContentWidth = self.collectionView!.bounds.width - layout.sectionInset.left - layout.sectionInset.right 
    let numberOfCellsPerRow: CGFloat = 10 
    let numberOfSpacesPerRow = numberOfCellsPerRow - 1 
    let cellWidth = (totalCellsContentWidth - (numberOfSpacesPerRow * desiredSpacing)/numberOfCellsPerRow) 
    layout.itemSize = CGSize(width: cellWidth, height: cellWidth) 
} 

假設你的細胞大小相同的minimumLineSpacing很簡單,但原本擴大包裝到下一行之前,以適應該行的最大細胞。正如你所看到的那樣,單元格間距有點複雜。

相關問題