Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get iPhone screen size programmatically? [duplicate]

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.

like image 403
bhavya kothari Avatar asked Jan 23 '13 08:01

bhavya kothari


2 Answers

You can use:

CGsize screenSize      = [[[UIScreen mainScreen] bounds] size];
CGFloat widthOfScreen  = screenSize.width;
CGFloat heightOfScreen = screenSize.height;
like image 154
Midhun MP Avatar answered Oct 14 '22 13:10

Midhun MP


You can know it with the UIScreen properties

[[UIScreen mainScreen] bounds].size.height;
[[UIScreen mainScreen] bounds].size.width;

for iPhone 5 and iPod touch 5gen the height is 568

for other iPhones and iPods the height is 480

Edit: on iOS 8 the height and the width deppend on the orientation, so this sizes are for portrait, on landscape this sizes will be for the width instead. So, best choice is to read both and do the max

like image 24
jcesarmobile Avatar answered Oct 14 '22 14:10

jcesarmobile