-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathUIDevice+Resolutions.m
43 lines (34 loc) · 1.31 KB
/
UIDevice+Resolutions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// UIDevice+Resolutions.m
// i48
//
// Created by Daniel Parnell on 15/02/13.
//
// See: http://stackoverflow.com/questions/12396545/ios-6-apps-how-to-deal-with-iphone-5-screen-size
//
#import "UIDevice+Resolutions.h"
@implementation UIDevice (Resolutions)
- (UIDeviceResolution)resolution
{
UIDeviceResolution resolution = UIDeviceResolution_Unknown;
UIScreen *mainScreen = [UIScreen mainScreen];
CGFloat scale = ([mainScreen respondsToSelector:@selector(scale)] ? mainScreen.scale : 1.0f);
CGFloat pixelHeight = (CGRectGetHeight(mainScreen.bounds) * scale);
if ([self userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if (scale >= 2.0f) {
if (pixelHeight == 960.0f)
resolution = UIDeviceResolution_iPhoneRetina4;
else if (pixelHeight >= 1136.0f)
resolution = UIDeviceResolution_iPhoneRetina5;
} else if (scale == 1.0f && pixelHeight == 480.0f)
resolution = UIDeviceResolution_iPhoneStandard;
} else {
if (scale >= 2.0f && pixelHeight >= 2048.0f) {
resolution = UIDeviceResolution_iPadRetina;
} else if (scale == 1.0f && pixelHeight == 1024.0f) {
resolution = UIDeviceResolution_iPadStandard;
}
}
return resolution;
}
@end