0

我有一個垂直UICollectionView與標準寬度和可變高度單元格。我有一個間距的問題。對於一個小區的每個高度的細胞後的間距是不同的:UICollectionView間距不等於

截圖的UICollectionView

回答

0

一種UICollectionView的具有delegate屬性。您應該在某些課程中實施UICollectionViewDelegateFlowLayout,例如View Controller。

此方法負責間距:

// Space around the section. 
func collectionView(_ collectionView: UICollectionView, 
        layout collectionViewLayout: UICollectionViewLayout, 
        insetForSectionAt section: Int) -> UIEdgeInsets { 
    return UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20) 
} 

// In case of vertical layout this is a vertical space between horizontal rows inside of each section 
func collectionView(_ collectionView: UICollectionView, 
        layout collectionViewLayout: UICollectionViewLayout, 
        minimumLineSpacingForSectionAt section: Int) -> CGFloat { 
    return 20 
} 

// Horizontal space between items in row 
func collectionView(_ collectionView: UICollectionView, 
        layout collectionViewLayout: UICollectionViewLayout, 
        minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { 
    return 20 
}