Search code examples
iosobjective-ciphoneuiscreen

How to get iPhone screen size programmatically?


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.


Solution

  • You can use:

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