LoginSignup
23
24

More than 5 years have passed since last update.

iOSアプリのスプラッシュ画像の取得方法

Last updated at Posted at 2015-01-15

iOSのアプリで画像を取得する際は

[UIImage imageNamed:"画像名"];

という形で取得しますね。

しかしスプラッシュ画像はそれではうまくいかないようです。

ビルド時に

[ LaunchImageのAssets Catalog登録名 ]-[ iOS Version ]-[ 画面の向き ]-[ 画面の高さ ][ スケール ].png

という感じにリネームされるようです。

リスト

アプリのLaunchImageを LaunchImage という名前でAssets Catalogに登録した場合

iOS ディスプレイ 画像名
iOS5,6 3.5inch LaunchImage
iOS5,6 3.5inch Retina LaunchImage@2x
iOS5,6 4.0inch Retina LaunchImage-568h@2x
iOS7,8 3.5inch Retina LaunchImage-700@2x
iOS7,8 4.0inch Retina LaunchImage-700-568h@2x
iOS8 4.7inch Retina LaunchImage-800-667h@2x
iOS8 5.5inch Retina Portrait LaunchImage-800-Portrait-736h@3x
iOS8 5.5inch Retina Landscape LaunchImage-800-Landscape-736h@3x

ソースコード例

LaunchImage.m
NSString *imageName = @"LaunchImage";
NSInteger osVer = floor( [[[UIDevice currentDevice] systemVersion] floatValue] ) * 100;
NSInteger height = CGRectGetHeight( [[UIScreen mainScreen] bounds] );

// 3.5 inch
if ( height < 568 ) {
    // iOS 7 〜
    if ( osVer >= 700 ) {
        imageName = [NSString stringWithFormat:@"%@-%zd", imageName, osVer];
    }
}
// 4.0 inch 〜
else if ( height < 736 ) {
    // iOS 7 〜
    if ( osVer >= 700 ) {
        imageName = [NSString stringWithFormat:@"%@-%zd-%zdh", imageName, osVer, height];
    }
    // 〜 iOS 6 
    else {
        imageName = [NSString stringWithFormat:@"%@-%zdh", imageName, height];
    }
}
// iPhone 6 Plus
else {
    NSString *orientation;
    switch ( [[UIApplication sharedApplication] statusBarOrientation] ) {
        case UIInterfaceOrientationPortrait:
        case UIInterfaceOrientationPortraitUpsideDown:
        case UIInterfaceOrientationUnknown:
            orientation = @"Portrait";
            break;

        case UIInterfaceOrientationLandscapeLeft:
        case UIInterfaceOrientationLandscapeRight:
            orientation = @"Landscape";
            break;
    }
    imageName = [NSString stringWithFormat:@"%@-%zd-%@-%zdh", imageName, osVer, orientation, height];
}
UIImage *launchImage = [UIImage imageNamed:imageName];

23
24
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
24