如何检测Retina高清显示屏?

时间:2014-09-23 11:04:18

标签: ios objective-c iphone cocoa-touch

UIScreen在iOS 8中有一个新的nativeScale属性,但文档中没有说到它。

@property(nonatomic, readonly) CGFloat nativeScale

还有scale属性,但文档称视网膜显示为2。

@property(nonatomic, readonly) CGFloat scale

我想知道是否有办法区分显示器。我之所以需要知道该设备是否具有Retina HD显示器,是因为我想根据显示器要求不同尺寸的图像。

感谢您的帮助!

2 个答案:

答案 0 :(得分:3)

下面非常适合检测iPhone6Plus上的显示类型。

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 3.0)
    NSLog(@"Retina HD"); 
else
    NSLog(@"Non Retina HD");

答案 1 :(得分:-1)

检查以下代码:

 CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);

NSLog(@"WIDTH:%f",screenSize.height);
 NSLog(@"WIDTH:%f",screenSize.width);



float height =screenSize.height;
float width = screenSize.width;

NSString *deviceType=@"";

if (height==1136.000000 && width==640.000000)
{
    deviceType =@"iPhone 5,5S and 5C Retina";
}
if (height==1920.000000 && width==1080.000000)
{
    deviceType =@"iPhone 6 Plus Retina Downsample";
}

if (height==2208.000000 && width==1242.000000)
{
    deviceType =@"iPhone 6 Plus Retina";
}

if (height==1334.000000 && width==750.000000)
{
    deviceType =@"iPhone 6 Retina";
}
if (height==960.000000 && width==640.000000)
{
    deviceType =@"iPhone 4 and 4S Retina";
}
if (height==480.000000 && width==320.000000)
{
    deviceType =@"iPhone 3g and 3gs Non retina ";
}

NSLog(@"Your Result:%@",deviceType);

参考:

iPhone Resoution