0

以下の関数を使用してcollectionViewセルサイズを変更することはできましたが、この関数を別の画面サイズで動作させるにはどうすればよいですか。ですから、例えば、私は高さと幅は、iPhoneは、iPhone/iPadでの各&すべての画面サイズのため、画面サイズを検出するchange UICollectionView画面サイズに応じたセルサイズ

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
      let width = UIScreen.main.bounds.width 
      let height = UIScreen.main.bounds.height 
      return CGSize(width: (width/5.5), height: (height/4.5)) 

     } 
+0

高さ/幅の値によってブレークポイントのように設定できます。つまり、縦横のスペースの量が異なる場合は、異なる値の戻り値を使用します。 –

答えて

3

その簡単なことを行うためにそこの方法であることをiPad上で異なるようにしたいです。ちょうどこのものに従ってください。

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

     if UIDevice().userInterfaceIdiom == .phone 
      { 
       switch UIScreen.main.nativeBounds.height 
       { 
       case 480: 
        print("iPhone Classic") 
       case 960: 
        print("iPhone 4 or 4S") 

       case 1136: 
        print("iPhone 5 or 5S or 5C") 

       case 1334: 
        print("iPhone 6 or 6S") 
       case 2208: 
        print("iPhone 6+ or 6S+") 
       default: 
        print("unknown") 
       } 
      } 

      if UIDevice().userInterfaceIdiom == .pad 
      { 
       if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad && 
        (UIScreen.main.bounds.size.height == 1366 || UIScreen.main.bounds.size.width == 1366)) 
       { 
        print("iPad Pro : 12.9 inch") 
       } 
       else if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad && 
        (UIScreen.main.bounds.size.height == 1024 || UIScreen.main.bounds.size.width == 1024)) 
      { 
        print("iPad 2") 
        print("iPad Pro : 9.7 inch") 
        print("iPad Air/iPad Air 2") 
        print("iPad Retina") 
      } 
      else 
      { 
        print("iPad 3") 
      } 
     } 

} 

だからあなたの要件に応じて高さ&幅を設定するためにこれを使用しています。 特定の画面に対してレイアウトを実行/設定することもできます。

お手伝いします。

関連する問題