如何获取当前启动图(LaunchImage)的图片文件名

1、通过获取全局info.plist中的UILaunchImages属性,这是一个字典,大概格式如下所示:

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
<__nsarraym 0x6000002413b0>(
{
    UILaunchImageMinimumOSVersion = "8.0";
    UILaunchImageName = "LaunchImage-800-Portrait-736h";
    UILaunchImageOrientation = Portrait;
    UILaunchImageSize = "{414, 736}";
},
{
    UILaunchImageMinimumOSVersion = "8.0";
    UILaunchImageName = "LaunchImage-800-667h";
    UILaunchImageOrientation = Portrait;
    UILaunchImageSize = "{375, 667}";
},
{
    UILaunchImageMinimumOSVersion = "7.0";
    UILaunchImageName = "LaunchImage-700";
    UILaunchImageOrientation = Portrait;
    UILaunchImageSize = "{320, 480}";
},
{
    UILaunchImageMinimumOSVersion = "7.0";
    UILaunchImageName = "LaunchImage-700-568h";
    UILaunchImageOrientation = Portrait;
    UILaunchImageSize = "{320, 568}";
}
)</__nsarraym>

2、遍历这个数组,找到图片尺寸为当前屏幕尺寸的字典,取出文件名即可
3、封装成工具类方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
+ (NSString *)getLaunchImageName
{
    // 取当前屏幕尺寸
    CGSize viewSize =SAApp.delegate.window.bounds.size;
 
    NSString *launchImage = nil;
    NSArray *imagesDict = [[SAMainBundle infoDictionary] valueForKey:@"UILaunchImages"];
    for(NSDictionary *dict in imagesDict) {
        // 遍历各字典中尺寸大小及图像方向,找到我们需要的那张图
        CGSize imageSize = CGSizeFromString([dict objForKey:@"UILaunchImageSize"]);
        NSString *orientation = [dict objForKey:@"UILaunchImageOrientation"];
 
        if (CGSizeEqualToSize(imageSize, viewSize) && [orientation isEqualToString:@"Portrait"]) {
            launchImage = [dict objForKey:@"UILaunchImageName"];
        }
    }
    return launchImage;
}

Leave a Reply