Best way to programmatically detect iPad/iPhone hardware

前端 未结 10 937
借酒劲吻你
借酒劲吻你 2020-11-27 14:14

The reason I need to find out is that on an iPad, a UIPickerView has the same height in landscape orientation as it does in portrait. On an iPhone it is different. The iPad

10条回答
  •  一个人的身影
    2020-11-27 14:43

    In Swift use userInterfaceIdiom instance property as-

    if UIDevice.current.userInterfaceIdiom == .phone {
         print("iPhone")
     }
    

    & For other devices -

      switch UIDevice.current.userInterfaceIdiom {
        case .pad:
            print("iPad")
        case .phone:
            print("iPhone")
        case .tv:
            print("TV")
        case .carPlay:
            print("carPlay")
        default: break;
      }
    

提交回复
热议问题