IOS 获取苹果手机的分辨率
IOS 获取苹果手机的分辨率,示例代码如下:
Utils.h
#import <Foundation/Foundation.h>
enum {
UIDevice_iPhone3 = 1, // iPhone 1,3,3GS Standard Resolution (320x480px)
UIDevice_iPhone4 = 2, // iPhone 4,4S High Resolution (640x960px)
UIDevice_iPhone5 = 3, // iPhone 5 High Resolution (640x1136px)
UIDevice_iPad2 = 4, // iPad 1,2 Standard Resolution (1024x768px)
UIDevice_iPad3 = 5 // iPad 3,4 High Resolution (2048x1536px)
}; typedef NSUInteger UIDeviceResolution;
@interface Utils : NSObject
#pragma mark - UIDevice
+ (UIDeviceResolution) currentResolution;
@end
Utils.m
#import "Utils.h"
static int _currentResolution = -1;
@implementation Utils
#pragma mark - UIDevice
+ (UIDeviceResolution) currentResolution {
if (_currentResolution > 0) {
return _currentResolution;
}
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
//NSLog(@" [[UIScreen mainScreen] respondsToSelector: @selector(scale)] == YES");
CGSize result = [[UIScreen mainScreen] bounds].size;
result = CGSizeMake(result.width * [UIScreen mainScreen].scale, result.height * [UIScreen mainScreen].scale);
if (result.height == 480) {
_currentResolution = UIDevice_iPhone3;
} else if(result.height == 960 ){
_currentResolution = UIDevice_iPhone4;
} else {
_currentResolution = UIDevice_iPhone5;
}
} else{
_currentResolution = UIDevice_iPhone3;
}
} else{
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
_currentResolution = UIDevice_iPad3;
} else {
_currentResolution = UIDevice_iPad2;
}
}
return _currentResolution;
}
@end
扩充:
获取当前手机的系统版本号:
[[[UIDevice currentDevice] systemVersion] floatValue]