iOS獲得AppIcon and LaunchImage's name(app圖標和啟動圖片名字)。本站提示廣大學習愛好者:(iOS獲得AppIcon and LaunchImage's name(app圖標和啟動圖片名字))文章只能為提供參考,不一定能成為您想要的結果。以下是iOS獲得AppIcon and LaunchImage's name(app圖標和啟動圖片名字)正文
在某種場景下,能夠我們須要獲得app的圖標稱號和啟動圖片的稱號。好比說app在前台時,收到了長途告訴然則告訴欄是不會有告訴提示的,這時候我想做個模仿告訴提醒,須要用到icon稱號;再好比在加載某個掌握器時,想設置該掌握器的配景圖片為啟動圖片,須要用到啟動圖片稱號。
而現實上icon圖片放在體系AppIcon文件夾裡,啟動圖片放在體系LaunchImage文件夾裡,取這些圖片的稱號和其他普通資本圖片稱號紛歧樣。
為了便利舉例子,我們先簡略粗魯點
假定以後項目只支撐iPhone裝備,而且只支撐豎屏;並且以後項目裡曾經設置好了AppIcon圖標和啟動圖片,
若何獲得icon圖標稱號和啟動圖片稱號呢 ?
上代碼和打印日記:
/** 獲得app的icon圖標稱號 */ - (void)getAppIconName{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; //獲得app中一切icon名字數組 NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"]; //取最初一個icon的名字 NSString *iconLastName = [iconsArr lastObject]; //打印icon名字 NSLog(@"iconsArr: %@", iconsArr); NSLog(@"iconLastName: %@", iconLastName); /* 打印日記: iconsArr: ( AppIcon29x29, AppIcon40x40, AppIcon60x60 ) iconLastName: AppIcon60x60 */ } /** 獲得app的啟動圖片稱號,並設置為本掌握器配景圖片 */ - (void)getLaunchImageName{ NSString *launchImageName = @""; //啟動圖片稱號變量 CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; //獲得與以後裝備婚配的啟動圖片稱號 if (screenHeight == 480){ //4,4S launchImageName = @"LaunchImage-700"; } else if (screenHeight == 568){ //5, 5C, 5S, iPod launchImageName = @"LaunchImage-700-568h"; } else if (screenHeight == 667){ //6, 6S launchImageName = @"LaunchImage-800-667h"; } else if (screenHeight == 736){ // 6Plus, 6SPlus launchImageName = @"LaunchImage-800-Landscape-736h"; } if (launchImageName.length < 1) return; //裝備啟動圖片為掌握器的配景圖片 UIImage *img = [UIImage imageNamed:launchImageName]; self.view.backgroundColor = [UIColor colorWithPatternImage:img]; }
打印以後只支撐iPhone裝備而且只支撐豎屏場景下的一切啟動圖片信息:
/** 打印app外面一切啟動圖片稱號信息 */ - (void)printAllLaunchImageInfo{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; //獲得一切啟動圖片信息數組 NSArray *launchImagesArr = infoDict[@"UILaunchImages"]; NSLog(@"launchImagesArr: %@", launchImagesArr); /* 打印日記:啟動圖片的名字是固定的 launchImagesArr: ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Landscape-736h"; UILaunchImageOrientation = Landscape; 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}"; } ) */ }
看到了,項目AppIcon圖標和啟動圖片信息,都可以從 [[NSBundle mainBundle] infoDictionary] 取得,以後這外面還包括了app的其他信息如版本、app稱號、裝備類型、支撐偏向。。。
打印一切信息看看:
/** 打印app工程設置裝備擺設信息 */ - (void)printInfoDictionary{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSLog(@"%@", infoDict); /* 打印日記: { BuildMachineOSBuild = 15G31; CFBundleDevelopmentRegion = en; CFBundleExecutable = TanTest; CFBundleIcons = { CFBundlePrimaryIcon = { CFBundleIconFiles = ( AppIcon29x29, AppIcon40x40, AppIcon60x60 ); }; }; CFBundleIdentifier = "net.tan.xxx"; CFBundleInfoDictionaryVersion = "6.0"; CFBundleInfoPlistURL = "Info.plist -- file:///Users/PX/Library/Developer/CoreSimulator/Devices/7020368B-C160-42C0-B3C5-5F958FA82EF5/data/Containers/Bundle/Application/77D8C333-A6AF-4183-B79A-A5BEDCD08E1A/TanTest.app/"; CFBundleName = TanTest; CFBundleNumericVersion = 16809984; CFBundlePackageType = APPL; CFBundleShortVersionString = "1.0"; CFBundleSignature = "????"; CFBundleSupportedPlatforms = ( iPhoneSimulator ); CFBundleVersion = 1; DTCompiler = "com.apple.compilers.llvm.clang.1_0"; DTPlatformBuild = ""; DTPlatformName = iphonesimulator; DTPlatformVersion = "9.3"; DTSDKBuild = 13E230; DTSDKName = "iphonesimulator9.3"; DTXcode = 0731; DTXcodeBuild = 7D1014; LSRequiresIPhoneOS = 1; MinimumOSVersion = "6.0"; UIDeviceFamily = ( ); UILaunchImageFile = LaunchImage; UILaunchImages = ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Landscape-736h"; UILaunchImageOrientation = Landscape; 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}"; } ); UILaunchStoryboardName = LaunchScreen; UIMainStoryboardFile = Main; UIRequiredDeviceCapabilities = ( armv7 ); UISupportedInterfaceOrientations = ( UIInterfaceOrientationPortrait ); } */ }
---------- 接上去我們再來在app既支撐iPhone和iPad裝備,又支撐橫屏和豎屏時,AppIcon和LaunchImage是如何的和若何獲得 ---
先上兩張圖,再上測試代碼:
測試代碼:
1、獲得AppIcon一切icon圖標稱號
/** 支撐iPhone和iPad, 獲得app的icon圖標稱號 */ - (void)getAppIconName{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; //獲得app中一切icon名字數組 NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"]; //取最初一個icon的名字 NSString *iconLastName = [iconsArr lastObject]; //打印icon名字 NSLog(@"iconsArr: %@", iconsArr); NSLog(@"iconLastName: %@", iconLastName); /* 打印日記(29pt和40pt iPhone和iPad都用到;60pt --- iPhone, 76pt和83.5pt --- iPad): iconsArr: ( AppIcon29x29, AppIcon40x40, AppIcon60x60, AppIcon76x76, "AppIcon83.5x83.5" ) iconLastName: AppIcon83.5x83.5 */ }
2、獲得在支撐iPhone和iPad開辟,支撐橫屏和豎屏時,獲得啟動圖片,並設為配景圖片代碼
(iPhone裝備只要在Plus, 即5.5英寸才有豎屏和橫屏兩套圖片,其他4、5、6豎屏橫屏共用一張啟動圖片)
/** 支撐iPhone和iPad, 支撐橫屏、豎屏, 獲得app的啟動圖片稱號,並設置為本掌握器配景圖片 */ - (void)getLaunchImageName{ NSString *launchImageName = @""; //啟動圖片稱號變量 CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; //屏幕高度 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; //屏幕寬度 //裝備界面偏向 UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; BOOL isPortrait = UIInterfaceOrientationIsPortrait(orientation);// 能否豎屏 BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);//能否橫屏 //獲得與以後裝備婚配的啟動圖片稱號 //4、4S 豎屏,橫屏 if ((isPortrait && screenHeight == 480) || (isLandscape && screenWidth == 480)){ launchImageName = @"LaunchImage-700"; } //5、5C、5S、iPod 豎屏,橫屏 else if ((isPortrait && screenHeight == 568) || (isLandscape && screenWidth == 568)){ launchImageName = @"LaunchImage-700-568h"; } //6、6S 豎屏,橫屏 else if ((isPortrait && screenHeight == 667) || (isLandscape && screenWidth == 667)){ launchImageName = @"LaunchImage-800-667h"; } //6Plus、6SPlus豎屏 else if (isPortrait && screenHeight == 736){ launchImageName = @"LaunchImage-800-Portrait-736h"; } //6Plus、6SPlus 橫屏 else if (isLandscape && screenWidth == 736){ launchImageName = @"LaunchImage-800-Landscape-736h"; } //iPad 豎屏 else if (isPortrait && screenHeight == 1024){ launchImageName = @"LaunchImage-700-Portrait"; } //iPad 橫屏 else if (isLandscape && screenWidth == 1024){ launchImageName = @"LaunchImage-700-Landscape"; } if (launchImageName.length < 1) return; //裝備啟動圖片為掌握器的配景圖片 UIImage *img = [UIImage imageNamed:launchImageName]; self.view.backgroundColor = [UIColor colorWithPatternImage:img]; }
3、打印出一切啟動圖片信息
/** 打印app外面一切啟動圖片稱號信息 */ - (void)printAllLaunchImageInfo{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; //獲得一切啟動圖片信息數組 NSArray *launchImagesArr = infoDict[@"UILaunchImages"]; NSLog(@"launchImagesArr: %@", launchImagesArr); /* 打印日記:啟動圖片的名字是固定的 launchImagesArr: ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Landscape-736h"; UILaunchImageOrientation = Landscape; 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}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-Portrait"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{768, 1024}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-Landscape"; UILaunchImageOrientation = Landscape; UILaunchImageSize = "{768, 1024}"; } ) */ }
4、打印一切設置裝備擺設信息
/** 打印app工程設置裝備擺設信息 */ - (void)printInfoDictionary{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSLog(@"%@", infoDict); /* 打印日記: { BuildMachineOSBuild = 15G31; CFBundleDevelopmentRegion = en; CFBundleExecutable = TanTest; CFBundleIcons = { CFBundlePrimaryIcon = { CFBundleIconFiles = ( AppIcon29x29, AppIcon40x40, AppIcon60x60, AppIcon76x76, "AppIcon83.5x83.5" ); }; }; CFBundleIdentifier = "net.tan.xxx"; CFBundleInfoDictionaryVersion = "6.0"; CFBundleInfoPlistURL = "Info.plist -- file:///Users/PX/Library/Developer/CoreSimulator/Devices/3246F9AE-1D73-4E4F-8DDF-F591DBE64F63/data/Containers/Bundle/Application/7DD6C793-F882-43CF-9897-1433411289E6/TanTest.app/"; CFBundleName = TanTest; CFBundleNumericVersion = 16809984; CFBundlePackageType = APPL; CFBundleShortVersionString = "1.0"; CFBundleSignature = "????"; CFBundleSupportedPlatforms = ( iPhoneSimulator ); CFBundleVersion = 1; DTCompiler = "com.apple.compilers.llvm.clang.1_0"; DTPlatformBuild = ""; DTPlatformName = iphonesimulator; DTPlatformVersion = "9.3"; DTSDKBuild = 13E230; DTSDKName = "iphonesimulator9.3"; DTXcode = 0731; DTXcodeBuild = 7D1014; LSRequiresIPhoneOS = 1; MinimumOSVersion = "9.0"; UIDeviceFamily = ( 1, ); UILaunchImageFile = LaunchImage; UILaunchImages = ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Landscape-736h"; UILaunchImageOrientation = Landscape; 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}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-Portrait"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{768, 1024}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-Landscape"; UILaunchImageOrientation = Landscape; UILaunchImageSize = "{768, 1024}"; } ); UILaunchStoryboardName = LaunchScreen; UIMainStoryboardFile = Main; UIRequiredDeviceCapabilities = ( armv7 ); UISupportedInterfaceOrientations = ( UIInterfaceOrientationPortrait, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight ); }*/ }
以上所述是小編給年夜家引見的iOS獲得AppIcon and LaunchImage's name(app圖標和啟動圖片名字),願望對年夜家有所贊助,假如年夜家有任何疑問請給我留言,小編會實時答復年夜家的。在此也異常感激年夜家對網站的支撐!