Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get screen size on iOS 8

I tried [[UIScreen mainScreen] bounds] to get the screen size of a resizable iPhone on Xcode 6 simulator. But it doesn't take into account the new screen width and screen height I assign to it.

Is there a better way to get the screen size? Even if I set the screen size to 320x800 the [[UIScreen mainScreen] bounds] returns me (CGRect) $0 = origin=(x=0, y=0) size=(width=768, height=1024)

enter image description here

like image 454
anuj Avatar asked Sep 02 '14 03:09

anuj


Video Answer


2 Answers

Do following

CGRect Rect=[[UIScreen mainScreen] bounds];

So it will preserves the bounds in the rect. try once.

like image 72
Yogesh More Avatar answered Oct 13 '22 08:10

Yogesh More


In Swift 4.0, 3.0

let screenRect:CGRect = UIScreen.main.bounds
like image 43
Kiryl Belasheuski Avatar answered Oct 13 '22 07:10

Kiryl Belasheuski