Screen size in pixel

CGRect screenBounds = [[UIScreen mainScreen] bounds];
That will give you the entire screen's resolution in points, so it would most typically be 320x480 for iPhones. Even though the iPhone4 has a much larger screen size iOS still gives back 320x480 instead of 640x960. This is mostly because of older applications breaking.

CGFloat screenScale = [[UIScreen mainScreen] scale];

This will give you the scale of the screen. For all iPhones and iPodTouches that do NOT have Retina Displays will return a 1.0f, while Retina Display devices will give a 2.0f.

Now if you want to get the pixel width & height of the iOS device screen you just need to do one simple thing.

CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);

By multiplying by the screen's scale you get the actual pixel resolution.

The usefulness of this code is that it will work in later products by Apple, such as if the iPad ever gets a Retina Display then using the scale will always get you the real pixel resolution.

A good read on the difference between points and pixels in iOS can be read here:http://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW7

See the UIScreen Reference:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html

if([[UIScreen mainScreen] respondsToSelector:NSSelectorFromString(@"scale")]) {     if ([[UIScreen mainScreen] scale] < 1.1)         NSLog(@"Standard Resolution Device");     if ([[UIScreen mainScreen] scale] > 1.9)         NSLog(@"High Resolution Device"); }
转帖: http://stackoverflow.com/questions/4779221/in-iphone-app-how-to-detect-the-screen-resolution-of-the-device




你可能感兴趣的:(ios,apple,iPhone,ipad,reference)