Xcode 5 & Asset Catalog: How to reference the LaunchImage?

前端 未结 14 1558
萌比男神i
萌比男神i 2020-11-28 18:17

I am using Xcode 5\'s Asset Catalog, and I would like to use my LaunchImage as the background image of my home view (a pretty common practice to make the transi

14条回答
  •  星月不相逢
    2020-11-28 18:51

    - (NSString *)splashImageNameForOrientation:(UIInterfaceOrientation)orientation {
        CGSize viewSize = self.view.bounds.size;
        NSString* viewOrientation = @"Portrait";
        if (UIDeviceOrientationIsLandscape(orientation)) {
            viewSize = CGSizeMake(viewSize.height, viewSize.width);
            viewOrientation = @"Landscape";
        }
    
        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"]])
                return dict[@"UILaunchImageName"];
        }
        return nil;
    }
    

提交回复
热议问题