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 ?
Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.
You can get the device screen width via the screen. width property. Sometimes it's also useful to use window. innerWidth (not typically found on mobile devices) instead of screen width when dealing with desktop browsers where the window size is often less than the device screen size.
Screen size measurements for smartphones are calculated by measuring diagonally from the upper left-hand corner of the screen to the lower right-hand corner*. These measurements are expressed in inches.
So here is a simple solution to get the dimensions of a view in android. Step 1 − Create a new project in Android Studio,go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
I haven't tried but it should be..
var bounds = UIScreen.main.bounds var width = bounds.size.width var height = bounds.size.height
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With