LoginSignup
32
29

More than 5 years have passed since last update.

UICollectionViewのセルサイズ調整

Posted at

よく忘れるので。

デバイスサイズに応じてUICollectionView内のセルサイズを変更したい場合の方法。

//UICollectionViewDelegateFlowLayoutプロトコルを指定しておきます。
class HogeViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
...

// 希望のセルサイズを返す
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    return CGSizeMake(self.view.frame.size.width/2-12, 180)
}
32
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
29