-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUIImage+MMLaunchImage.m
More file actions
70 lines (58 loc) · 2.96 KB
/
UIImage+MMLaunchImage.m
File metadata and controls
70 lines (58 loc) · 2.96 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// UIImage+LaunchImage.m
//
// Matt Mayer
#import "UIImage+MMLaunchImage.h"
@implementation UIImage (MMLaunchImage)
+(UIImage *)launchImage {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
BOOL phone =[UIDevice currentDevice].userInterfaceIdiom ==UIUserInterfaceIdiomPhone;
BOOL landscape = UIInterfaceOrientationIsLandscape(orientation);
NSString *os_version = [[UIDevice currentDevice] systemVersion];
//check the ios7 key
NSArray *ios7LaunchImages = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
if (ios7LaunchImages!=nil) {
NSString *orientationString = @"Portrait";
if (!phone && landscape) {
orientationString = @"Landscape";
}
//filter down the array to just the matching elements
UIWindow *mainWindow = [UIApplication sharedApplication].keyWindow;
if (mainWindow == nil) {
mainWindow = [[UIApplication sharedApplication].windows firstObject];
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"UILaunchImageMinimumOSVersion <= %@ AND UILaunchImageOrientation = %@ AND UILaunchImageSize = %@",os_version,orientationString,NSStringFromCGSize(mainWindow.bounds.size) ];
NSArray *suitableLaunchImages = [ios7LaunchImages filteredArrayUsingPredicate:predicate];
NSString *imageName = [[suitableLaunchImages lastObject] objectForKey:@"UILaunchImageName"];
UIImage *image = [UIImage imageNamed:imageName];
if (image!=nil) {
return image;
}
}
//check the pre-ios7 key
NSString* baseName = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImageFile"];
if (baseName==nil)
baseName = @"Default";
if(phone) {
BOOL fourinch = ([UIScreen mainScreen].bounds.size.height == 568.0);
return fourinch ? [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h",baseName]] : [UIImage imageNamed:baseName];
} else {
UIImage *image = nil;
if(orientation == UIInterfaceOrientationPortraitUpsideDown) {
image =[UIImage imageNamed:[NSString stringWithFormat:@"%@-PortraitUpsideDown",baseName]];
} else if (orientation == UIInterfaceOrientationLandscapeLeft) {
image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeLeft",baseName]];
} else if( orientation == UIInterfaceOrientationLandscapeRight) {
image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeRight",baseName]];
}
if (image!=nil) {
return image;
}
image = [UIImage imageNamed:[NSString stringWithFormat:(landscape?@"%@-Landscape":@"%@-Portrait"),baseName]];
if (image!=nil) {
return image;
}
return [UIImage imageNamed:[NSString stringWithFormat:(landscape?@"%@-Landscape~ipad":@"%@-Portrait~ipad"),baseName]];
}
}
@end