IOS 判断设备屏幕尺寸、分辨率

时间:2021-12-22 06:59:07
根据屏幕尺寸和分辨率,ios现在数起来有6个版本。

iOS 设备现有的分辨率如下:
iPhone/iPod Touch
普通屏   320像素 x 480像素 iPhone 、3G、3GS,iPod Touch 、、
: Retina 屏   640像素 x 960像素 iPhone 、4S,iPod Touch
: Retina 屏 640像素 x 1136像素 iPhone ,iPod Touch iPad
普通屏        768像素 x 1024像素 iPad , iPad2,iPad mini
Retina屏      1536像素 x 2048像素 New iPad,iPad UIDevice+Resolutions.h //
// UIDevice+Resolutions.h
// Test_common
//
// Created by wangzhipeng on 13-1-30.
// Copyright (c) 2013年 com.comsoft. All rights reserved.
// #import enum {
// iPhone 1,3,3GS 标准分辨率(320x480px)
UIDevice_iPhoneStandardRes = ,
// iPhone 4,4S 高清分辨率(640x960px)
UIDevice_iPhoneHiRes = ,
// iPhone 5 高清分辨率(640x1136px)
UIDevice_iPhoneTallerHiRes = ,
// iPad 1,2 标准分辨率(1024x768px)
UIDevice_iPadStandardRes = ,
// iPad 3 High Resolution(2048x1536px)
UIDevice_iPadHiRes =
}; typedef NSUInteger UIDeviceResolution; @interface UIDevice (Resolutions){ } + (UIDeviceResolution) currentResolution; + (BOOL)isRunningOniPhone5; + (BOOL)isRunningOniPhone; @end UIDevice+Resolutions.m //
// UIDevice+Resolutions.m
// Test_common
//
// Created by wangzhipeng on 13-1-30.
// Copyright (c) 2013年 com.comsoft. All rights reserved.
// #import "UIDevice+Resolutions.h" @implementation UIDevice (Resolutions) + (UIDeviceResolution) currentResolution {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
result = CGSizeMake(result.width * [UIScreen mainScreen].scale, result.height * [UIScreen mainScreen].scale);
if (result.height <= 480.0f)
return UIDevice_iPhoneStandardRes;
return (result.height > ? UIDevice_iPhoneTallerHiRes : UIDevice_iPhoneHiRes);
} else
return UIDevice_iPhoneStandardRes;
} else
return (([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) ? UIDevice_iPadHiRes : UIDevice_iPadStandardRes);
} + (BOOL)isRunningOniPhone5{
if ([self currentResolution] == UIDevice_iPhoneTallerHiRes) {
return YES;
}
return NO;
} + (BOOL)isRunningOniPhone{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
} @end