2016-09-25 9 views
2

単一のセルだけが返された場合は、UICollectionviewセルの中央揃えが必要です。私はこれを使用しています中央の単一のコレクションビューセルの整列

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 

     if self.imageSelected.count == 1 
     { 
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { 
       return UIEdgeInsetsMake(0, 100, 0, 0) 
      } 
     } 

     return self.imageSelected.count 

    } 

上記のコードは、カウントが1の場合に選択されていますが、セルの位置に動きがないと表示されています。

私もこれを試してみましたが、ここでそれもブレークポイント

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { 
     if self.imageSelected.count == 1 { 
      return UIEdgeInsetsMake(0, 100, 0, 0) 
     } else { 
      return UIEdgeInsetsMake(0, 0, 0, 0) 
     } 
    } 

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 

     return self.imageSelected.count 

    } 
+0

これはカスタムコレクションビューのレイアウトです。 – TheCodingArt

答えて

-1

は、あなたの質問に、コードの代わりに、あなたのビューコントローラにこれを入れて打っていません。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { 
    if self.imageSelected.count == 1 { 
     return UIEdgeInsetsMake(0, 100, 0, 0) 
    } else { 
     return UIEdgeInsetsMake(0, 0, 0, 0) 
    } 
} 

これは、コードを作ることあなたは仕事を創りました。セルを中央に揃える方法についてより正確な答えが必要な場合は、質問してください。私はあなたに手伝ってくれるように時間と労力をかけます:)

+0

あなたが言ったものの、それは動作しません、それはブレークポイントを打つことさえありません。 – leaner122

+0

'UICollectionViewDelegateFlowLayout'を実装して、コレクションビューのレイアウトのデリゲートを自己に設定します – Christoph

+0

これをviewDidLoad()、self.collectionView!.delegate = self;で行いました。それはまだ仕事をしない – leaner122

関連する問題