iosswiftcocoa-touchuiscreencgsize

How to get device width and height?


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 ?


Solution

  • I haven't tried but it should be..

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