iOS get physical screen size programmatically?

前端 未结 11 1942
情话喂你
情话喂你 2020-12-15 03:11

Is this possible? I want the number of inches, not the number of pixels. I know it is approximately 160 ppi. But not exactly.

11条回答
  •  情话喂你
    2020-12-15 03:40

    note: screen rotation matters here

    extension UIScreen {
        var physicalSize:CGSize {
            return CGSize(width: bounds.width*scale, height: bounds.height*scale)
        }
    }
    

    using:

    print(UIScreen.main.physicalSize)
    

提交回复
热议问题