How to get device width and height? How to get device width and height? ios ios

How to get device width and height?


I haven't tried but it should be..

var bounds = UIScreen.main.boundsvar width = bounds.size.widthvar height = bounds.size.height


Swift 4.2

let screenBounds = UIScreen.main.boundslet width = screenBounds.widthlet height = screenBounds.height


@Houssni 's answer is correct, but since we're talking Swift and this use case will come up often, one could consider extending CGRect similar to this:

extension CGRect {    var wh: (w: CGFloat, h: CGFloat) {        return (size.width, size.height)    }}

Then you can use it like:

let (width, height) = UIScreen.mainScreen().applicationFrame.wh

Hooray! :)