How can one get the dimensions of the screen in iOS?
Currently, I use:
lCurrentWidth = self.view.frame.size.width;
lCurrentHeight = self.view.frame.size.height;
in viewWillAppear:
and willAnimateRotationToInterfaceOrientation:duration:
The first time I get the entire screen size. The second time i get the screen minus the nav bar.
Careful, [UIScreen mainScreen] contains status bar as well, if you want to retrieve the frame for your application (excluding status bar) you should use
I've translated some of the above Objective-C answers into Swift code. Each translation is proceeded with a reference to the original answer.
Main Answer
Simple Function Answer
Device Orientation Answer
Log Answer
It's very, very easy to get your device size as well as take into account the orientation:
Make use of these
Structs
to know useful info about the current device in Swift 3.0You can place these macros in your pch file and used at anywhere in project by using "SCREEN_WIDTH"
and "SCREEN_HEIGHT"
Example of using:
Here i have updated for swift 3
applicationFrame deprecated from iOS 9
In swift three they have removed () and they have changed few naming convention, you can refer here Link