iOS 獲取啟動圖截圖

+ (UIImage *)getLaunchImage {
    UIImage *image = nil;
    CGSize viewSize = [[UIScreen mainScreen] bounds].size;
    NSString *viewOrientation = @"Portrait";    //橫屏請設(shè)置成 @"Landscape"
    NSString *launchImage = nil;
    //1.通過launchimage獲取
    NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    for (NSDictionary* dict in imagesDict) {
        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
        if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
            launchImage = dict[@"UILaunchImageName"];
            image = [UIImage imageNamed:launchImage];
        }
    }
    if (!image) {
        //加載指定啟動圖
        image = [UIImage imageNamed:@"LaunchImage-xxx(自定義圖片)"];
    }
//2.通過launchscreen.storyboard獲取
   if (!image) {
        //拿到LaunchScreen.StoryBoard并生成一個控制器
  NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *storyboardName = [infoDic valueForKey:@"UILaunchStoryboardName"];
    if (storyboardName.length>0) {
        // 轉(zhuǎn)換為UIImage
    CGRect frame = [UIScreen mainScreen].bounds;
    UIView *view = vc.view;
    UIGraphicsBeginImageContext(frame.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
  }
    }
    return image;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容