程式碼獲取 LaunchImage、AppIcon 圖片名稱

weixin_34116110發表於2017-05-17
在Images.xcassets檔案下的LaunchImage、AppIcon圖片名稱獲取方法如下:
// 獲取LaunchImage圖片名稱
static inline NSString * launchImageName() {
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    NSString *viewOrientation = @"Portrait"; //預設為豎屏,橫屏設定為 @"Landscape"
    NSString *launchImageName = nil;
    NSArray *launchImages = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    for(NSDictionary* dict in launchImages) {
        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
        if(CGSizeEqualToSize(imageSize, screenSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
            launchImageName = dict[@"UILaunchImageName"];
        }
    }
    return launchImageName;
}
// 獲取AppIcon圖片名稱
static inline NSString * appIconName() {
    NSArray *iconImages = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
    return [iconImages lastObject];
}

相關文章