Ios 如何将适当的Default.png加载到UImageView?

Ios 如何将适当的Default.png加载到UImageView?,ios,uiimageview,uiimage,splash-screen,Ios,Uiimageview,Uiimage,Splash Screen,我有默认的启动屏幕,名称如下: 违约-568h@2x.png,Default-grait.png,Default.png,Default@2x.png等等,适用于所有类型的设备 我知道系统会自动为特定设备选择合适的启动屏幕并显示它 问题:是否可能知道系统选择了哪个图像?如何将系统选择的适当图像加载到UIimageView 我试过这个: UIImageView *splashView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, scree

我有默认的启动屏幕,名称如下: 违约-568h@2x.png,Default-grait.png,Default.png,Default@2x.png等等,适用于所有类型的设备

我知道系统会自动为特定设备选择合适的启动屏幕并显示它

问题:是否可能知道系统选择了哪个图像?如何将系统选择的适当图像加载到UIimageView

我试过这个:

UIImageView *splashView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
splashView.image=[UIImage imageNamed:@"Default.png"];
但对于所有类型的设备(iPhone 4、5、iPad),它只加载名为Default.png的图像


我需要手动管理吗?我的意思是在识别设备类型后加载相应的图像?

编辑:检查并退出

你如何使用这条线来提供闪屏,无论你是否有视网膜显示

UIImageView *splashView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
应用程序检测设备显示并相应地拍摄图像


如果设备有视网膜显示器,则需要Default@2x.png自动。

我为所有启动屏幕手动执行此操作:

 CGRect screenRect = [[UIScreen mainScreen] bounds];
 float screenWidth = screenRect.size.width;
 float screenHeight = screenRect.size.height;

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    splashView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
    if (screenHeight==568.0) {
         splashView.image=[UIImage imageNamed:@"Default-568h@2x.png"];//iPhone 5
    }else{
          splashView.image=[UIImage imageNamed:@"Default.png"]; //other iPhones
    } 
} else {
    splashView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 20, screenWidth, screenHeight-20)];
    splashView.image=[UIImage imageNamed:@"Default-Portrait.png"];// iPads
}

我在遇到同样的问题后发现了这个问题。似乎如果您使用
[UIImage imagedNamed:@“Default”]
iOS将检测视网膜与非视网膜,并应用
@2x
,但不会检测iPhone 5并应用
-568h

我提出的解决方案是在UIImage上编写一个类别,检查主窗口的高度,并返回适当的图像(如果存在):

@interface UIImage (Compatible)

+ (UIImage *)compatibleImageNamed:(NSString *)name;

@end

@implementation UIImage (Compatible)

+ (UIImage *)compatibleImageNamed:(NSString *)name {

    if ([[UIScreen mainScreen] bounds].size.height==568.0){

        NSString *extension = [name pathExtension];

        NSString *iPhone5Name = [[name stringByDeletingPathExtension] stringByAppendingString:@"-568h"];

        if (extension.length!=0)
            iPhone5Name = [iPhone5Name stringByAppendingPathExtension:extension];

        UIImage *image = [UIImage imageNamed:iPhone5Name];

        if (image)
            return image;

    }

    return [UIImage imageNamed:name];
}

@end
然后,在我知道的任何地方,我都想加载一个图像,该图像也有我使用的iPhone 5版本:


[UIImage compatibleImageNamed:@“MyImage”]

您应该更改以下内容:

[UIImage imageNamed:@"Default.png"];


它不检测默认值-568h@2x.png对于iPhone 5和iPadI的Default-grait.png检查了您的修改,但这与我的问题无关;iOS将只检测非视网膜。要检测两个版本,只要您的目标是iOS 4或更高版本,就应该使用Default.png,您应该能够在不指定扩展名的情况下使用
@“Default”
。不管怎样,我已经编辑了我的例子来处理扩展。你能解释一下原因来改进你的答案吗?
[UIImage imageNamed:@"Default"];