Reputation: 151
I put this code in my app:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
NSLog(@"screenWidth : %f", screenWidth);
NSLog(@"screenHeight : %f", screenHeight);
The I start the simulator with Iphone 3.5 inch. The log prints 320.000000 for the width.
However, when I then change the device for the simulator, selecing 4inch, it stills shows the same width. Why? Whats wrong. It is supposed to be 640 px in width for Iphone 4 and above, doesnt it?
Upvotes: 0
Views: 1383
Reputation: 4826
According to the Apple Docs, that value is the "default logical value". If you want to know the actual size, take a look at [[UIScreen mainScreen] scale]
. For retina devices, this value is 2.0
, so do [[UIScreen mainScreen] bounds].size.width * [[UIScreen mainScreen] scale]
Upvotes: 1
Reputation: 4272
In the simulator screenWidth will be always 320 ( right now iphone4-5 ). You can check the scale with [[UIScreen mainScreen] scale];
scale will be 2.0 if you running on retina iPhone.
Upvotes: 1
Reputation: 50089
no the width is always 320 POINTS / DPIs -- what you mean is that it really has 640 PIXELS (which are device dependant)
Calculations are always based on device INDEPENDENT points
UIScreen offers a scalingFactor that translates dpi <> pixels
Upvotes: 0