How to get device width and height?

Rigel Networks picture Rigel Networks · Jun 6, 2014 · Viewed 83.4k times · Source

In Objective-C we can get device width and height by using following code :

CGRect sizeRect = [UIScreen mainScreen].applicationFrame
float width = sizeRect.size.width
float height = sizeRect.size.height

How can do this in with Swift ?

Answer

iPatel picture iPatel · Jun 6, 2014

I haven't tried but it should be..

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