How to get device width and height?
I haven't tried but it should be..
var bounds = UIScreen.main.bounds
var width = bounds.size.width
var height = bounds.size.height
Swift 4.2
let screenBounds = UIScreen.main.bounds
let width = screenBounds.width
let 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! :)