Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 888
Divya Bhaloidiya Avatar asked Jun 06 '14 15:06

Divya Bhaloidiya


People also ask

How do I find my device width and height?

Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.

How do you find the width of a device?

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.

How can I check my phone 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.

How do you find the height and width of a view?

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.


1 Answers

I haven't tried but it should be..

var bounds = UIScreen.main.bounds var width = bounds.size.width var height = bounds.size.height 
like image 91
iPatel Avatar answered Oct 07 '22 21:10

iPatel