본문 바로가기

개발

화면의 세로 사이즈로 디바이스 구별

좀 더 복잡하고 기능이 많은 API들이 있지만 그냥 간단하게 아이폰과 아이패드만 구별하면 익스텐션이다
화면의 가로 사이즈로 구별하기에는 동일한 사이즈를 사용하는 기기가 있어서 세로 사이즈를 기준으로 구별했다.

  extension CGFloat {
      //MARK: - 화면 리사이즈
      /*
       375 * 812 X @3x    1125px × 2436px    2436px × 1125px
       414 * 736 6+, 6s+, 7+, 8+ @3x    1242px × 2208px    2208px × 1242px
       375 * 667 6, 6s, 7, 8    750px × 1334px    1334px × 750px
       320 * 568 5s, SE    640px × 1136px
       1024 x 1366 iPad Pro 12.9-inch (2nd generation)    2048 x 2732
       1112 x 834 iPad Pro 10.5-inch    2224 x 1668
       768 x 1024 iPad Pro (9.7-inch), Air, Air 2, Mini 4     1536 x 2048
       */
     
      func changeCalendarHeight(screenHeight: Int) -> CGFloat {
     
          //let screenHeight = UIScreen.main.bounds.size.height
          var calHeight : CGFloat = 0
         
          switch screenHeight {
     
          case 568: // SE
              calHeight = 288
     
          case 667: // 6, 6s, 7, 8
              calHeight = 343
     
          case 736: // 6+, 6s+, 7+, 8+
              calHeight = 382
     
          case 812: // iphone X
              calHeight = 343
     
          case 1024:
              calHeight = 736
     
          case 1112:
              calHeight = 90
     
          case 1366:
              calHeight = 90
     
          default: break
     
          }
         
          return calHeight
      }
  }
 
  var t = Int(UIScreen.main.bounds.size.height)
  newCalHeight = newCalHeight.changeCalendarHeight(screenHeight: t)