How to get iOS device screen height and width [duplicate]
Asked Answered
L

2

23

Possible Duplicate:
IPhone/IPad: How to get screen width programmatically?
How to get orientation-dependent height and width of the screen?

Accounting for the various iOS devices and orientations, what is the simplest approach to getting the current screen resolution, including height and width?

Libra answered 3/1, 2013 at 8:16 Comment(5)
Or also How to get orientation-dependent height and width of the screen?.Spic
Here you have it: #3655604Linetta
Neither of those techniques worked for me.Libra
What exactly didn't work? We can't help you if you don't tell us what your actual problems are.Spic
@KurtRevis thanks for your feedback. I realize now that I wasn't accounting for the fact that in landscape, the height effectively becomes the width.Libra
S
81

UIScreen is your friend here.

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
Sentiment answered 3/1, 2013 at 8:21 Comment(2)
Thank you. I realize now that I wasn't accounting for the fact that in landscape, the height effectively becomes the width.Libra
If you combine the above with UIDevice, you get a nice ENUM that tells you exactly the orientation of the device. UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;Curd
B
9
CGRect screenBounds = [[UIScreen mainScreen] bounds];

That will give you the entire screen's resolution in points, so it would most typically be 320x480 for iPhones. Even though the iPhone4 has a much larger screen size iOS still gives back 320x480 instead of 640x960. This is mostly because of older applications breaking.

Hope it helps you..

Brandiebrandise answered 3/1, 2013 at 8:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.