2017-08-08 10 views
0

私はTinderのようなユーザーの譜表写真を表示するためにコレクションビューを使用したいと思います。私はcollectionviewを配置し、を有効にしてのページングを有効にしました。しかし、私は各ページに6枚の写真を表示する方法を知らない。これどうやってするの?Collectionviewとページング

これは私が欲しいものです:

最初のページ:

enter image description here

2番目のページ:セットので

enter image description here

私はゼロ、すべての間隔の設定を使用さまざまな画面サイズのストーリーボードの問題との間隔。

マイコレクションビューの設定と結果:

enter image description here

結果:

enter image description here

は、だから私は、ページごとに6枚の写真を見せたいです。これを実現するには?

+0

私はここで良い解決策を見つけると思います:https://stackoverflow.com/questions/16678474/uicollectionview-horizo​​ntal-paging-can-i-use-flow-レイアウト – DonMag

答えて

0

特定のセル数を表示するには、セルのサイズを計算する必要があります。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
    let numberOfRows = 2 
    let numberOfColumns = 3 

    let height = collectionView.frame.size.height/numberOfRows 
    let width = collectionView.frame.size.width/numberOfColumns 

    let cellSize = CGSize(width: width, height: height) 

    return cellSize 
} 

あなたのレイアウト構成が静的であるので、あなたはそれを速く作るために一度だけ、それを計算することができます:このような何か

class MyVC: UIViewController { 

    private let cellSize: CGSize = CGSize(width: collectionView.frame.width/numberOfColumns, height: collectionView.frame.height/numberOfRows) // or create a computed property 

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
     return cellSize 
    } 
} 

このコードは、テストされていないが、多分あなたは、いくつかのパディングを追加する必要がありますが、あなたが得ますアイデア。もう1つのオプションは、自分自身を実装することですUICollectionViewLayoutサブクラス