How to get device width and height?

后端 未结 12 1120
离开以前
离开以前 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条回答
  •  既然无缘
    2020-12-23 15:03

    (Swift 3) Keep in mind that most width and height values will be based on device's current orientation. If you want a consistent value that is not based on rotation and offers results as if you were in a portrait-up rotation, give fixedCoordinateSpace a try:

    let screenSize = UIScreen.main.fixedCoordinateSpace.bounds
    

提交回复
热议问题