How to get iPhone screen size programmatically?

bhavya kothari picture bhavya kothari · Jan 23, 2013 · Viewed 19.3k times · Source

Possible Duplicate:
How to get screen size using code?

 NSLog(@"Top Left View : Width %f height%f",self.topLeftView.frame.size.width,self.topLeftView.frame.size.height);

I have dragged the "View" from object library and put it on xib file.

But what if I want to get the screen size to check whether its iphone 4,iPhone 3 or iphone 5 or any iOS Device.

So that I can arrange other views accordingly.

Answer

Midhun MP picture Midhun MP · Jan 23, 2013

You can use:

CGsize screenSize      = [[[UIScreen mainScreen] bounds] size];
CGFloat widthOfScreen  = screenSize.width;
CGFloat heightOfScreen = screenSize.height;