Screen size in pixel

Screen size in pixel,第1张

概述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

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");     UIScreen mainScreen] scale] > 1.9)         "High Resolution Device"); }
转帖: http://stackoverflow.com/questions/4779221/in-iphone-app-how-to-detect-the-screen-resolution-of-the-device 总结

以上是内存溢出为你收集整理的Screen size in pixel全部内容,希望文章能够帮你解决Screen size in pixel所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1089339.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存