简体   繁体   中英

xcode simulator iphone screen size

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?

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.

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]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM