2017-01-03 11 views
0

私は水平方向にスクロールするUICollectionViewを持っていて、一度に1つのセルを画面上に表示したいと思います。インセット、間隔、セクションのインセット(両方とも、プログラムおよびXcodeで検査官中で作業する方法を見つけ出すのに苦労した後Swift 3 - パディング付きUICollectionView Centerセル

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath) as! Cell 

    let width = collectionView.bounds.size.width - 40 
    let height = collectionView.bounds.size.height - 40 

    cell.bounds.size = CGSize(width: CGFloat(width), height: CGFloat(height)) 

    return cell 
} 

そして:

私はプログラム的に以下の方法でセルの幅と高さを設定しています)私は何を設定する必要があるのか​​、どこに設定する必要があるのか​​分かりません。ここ

は私の所望の間隔を示す図である:20を左 enter image description here

答えて

1
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize { 
    return CGSize(width: UIScreen.main.bounds.width - 40, height: yourCollectionViewHeight - 40) 
} 

- 細胞間のwidth = 20

間隔でストーリーボードにFooter SizeHeader Sizeを追加 - ストーリーボードにMinimum Spacingを追加= 40

enter image description here

私はいくつかの間違いを犯す可能性があり、あなたのレイアウトを正確には得られませんが、あなたがそのアイデアを得ることを望みます。

関連する問題