How to get device width and height?

后端 未结 12 1173
离开以前
离开以前 2020-12-23 14:13

In Objective-C we can get device width and height by using following code :

CGRect sizeRect = [UIScreen mainScreen].applicationFrame
float width = sizeRect.         


        
12条回答
  •  猫巷女王i
    2020-12-23 15:17

    In Swift 4 I had to use NSScreen.main?.deviceDescription

    let deviceDescription = NSScreen.main?.deviceDescription          
    let screenSize = deviceDescription![.size]
    let screenHeight = (screenSize as! NSSize).height
    

提交回复
热议问题