2016-08-02 12 views
0

各行に2つのアイテムがあり、各アイテムはアイテム間の間隔に等しいパディングを持つレイアウトを作成したいと思います。例えば、アイテム間の間隔は、アイテムとエッジ間の間隔と等しくなければならない。私はアイテム間で水平に等間隔になるように管理しましたが、垂直方向には大きすぎます。どうすれば修正できますか?UICollectionView - 各行に2行と等しい間隔があります。

enter image description here

自分のコード

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
    return CGSizeMake(self.view.frame.width/2 - 10, self.view.frame.width/2 - 10) 
} 

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

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat { 
    return 5 
} 

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { 
    return UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5) 
} 

答えて

0

UICollectionViewFlowLayout二つの性質があります "グリッド内のアイテムの行との間に使用するための最小間隔"

  • minimumLineSpacing
  • minimumInteritemSpacing "同じ行のアイテム間で使用する最小間隔。"

これら2つの値を微調整して何が起こるかを確認してください。

関連する問題