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

根据屏幕尺寸和分辨率,ios现在数起来有6个版本。



iOS 设备现有的分辨率如下:

iPhone/iPod Touch

普通屏                           320像素 x 480像素       iPhone 1、3G、3GS,iPod Touch 123

32 Retina 屏             640像素 x 960像素        iPhone 4、4S,iPod Touch 4

169 Retina 屏               640像素 x 1136像素      iPhone 5,iPod Touch 5



iPad

普通屏                  768像素 x 1024像素      iPad 1, iPad2,iPad mini

Retina屏                  1536像素 x 2048像素     New iPad,iPad 4



 



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      = 1,

    // iPhone 4,4S 高清分辨率(640x960px)

    UIDevice_iPhoneHiRes            = 2,

    // iPhone 5 高清分辨率(640x1136px)

    UIDevice_iPhoneTallerHiRes      = 3,    

    // iPad 1,2 标准分辨率(1024x768px)

    UIDevice_iPadStandardRes        = 4,    

    // iPad 3 High Resolution(2048x1536px)

    UIDevice_iPadHiRes              = 5               

}; 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 > 960 ? 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

 

你可能感兴趣的:(ios)