4

I am trying to get size the of the screen connected to apple tv, is it possible? I have been looking into the documentation provided by apple related to UIScreen but couldn't find anything new except nativeBounds which is same as bounds.

let screenSize = UIScreen.mainScreen().bounds.size
let nativeBound = UIScreen.mainScreen().nativeBounds.size

Both of them are giving me output in pixels, but i need the screen/monitor size (inch) as well. So that i could arrange the display accordingly.

Thanks in advance!

MQ.
  • 365
  • 6
  • 28

1 Answers1

4

First of all, UIScreen.mainScreen().bounds returns the size of the screen in points, not pixels. See the docs.

UIScreen.mainScreen().nativeBounds returns the screen size in pixels.

To find the actual screen size (in an absolute unit of size such as inches), you would need to know the physical size of a pixel, and multiply that by the nativeBounds.

However, I don't think iOS has an API to retrieve pixel size.

paulvs
  • 11,963
  • 3
  • 41
  • 66
  • So that is the particular point i am looking for screenSizeInPixels can be found through let nativeBound = UIScreen.mainScreen().nativeBounds.size. – MQ. Mar 14 '16 at 03:49
  • 1
    True. `nativeBounds` returns the size in pixels, which saves you from doing the calculation. I'll update my answer. – paulvs Mar 14 '16 at 09:04