Xcode 5使用不同的映像,具体取决于使用的是iOS 7还是更低版本

Xcode 5使用不同的映像,具体取决于使用的是iOS 7还是更低版本,ios,objective-c,xcode,Ios,Objective C,Xcode,现在使用Xcode 5是否有一种聪明的方法可以根据应用程序是否为iOS7在应用程序中加载不同的图像 我能想到的最佳解决方案是在iOS7所需的图像末尾附加“_7”,然后在应用程序中使用图像时,我可以: NSString *OSSuffix = OSVersion == 7 ? @"_7" : @""; //would be define globally, also pseudo syntax [UIImage imageNamed:[NSString stringWithFormat:@"ima

现在使用Xcode 5是否有一种聪明的方法可以根据应用程序是否为iOS7在应用程序中加载不同的图像

我能想到的最佳解决方案是在iOS7所需的图像末尾附加“_7”,然后在应用程序中使用图像时,我可以:

NSString *OSSuffix = OSVersion == 7 ? @"_7" : @""; //would be define globally, also pseudo syntax
[UIImage imageNamed:[NSString stringWithFormat:@"imageName%@", OSSuffix]]; //can make a macro for this probably
但是,有没有更好的“内置”方式来处理新的资产目录或其他东西呢?

,根据设备类型自动加载568像素高的图像。由于没有提供该功能,我提出了一个到
UIImage
的补丁:


您可以使用相同的技巧根据一些自定义名称标记自动加载iOS7资源。同样需要注意的是:
UIImage
技巧使用方法swizzling,在生产中可能太神奇了。您的呼叫。

资产目录与此无关。仅仅因为一个新版本的操作系统而想要新的图像是不常见的,所以这个功能是你需要自己实现的。一个解决方案是让你所有的图像都通过一个imageProvider交付,那么至少你不需要到处复制代码。另外:如果(NSFoundationVersionNumber>NSFoundationVersionNumber_iOS_6_1)@borrden,当你的应用程序中有定制按钮和其他东西与iOS 7的其他部分不一样时,它看起来有点奇怪,iOS 6也一样。我确信很多当前的应用程序都会遇到这种问题抱歉,但是这与Xcode有什么关系?@dan78如果你读了这个问题,我会问Xcode 5中是否有新的功能来支持这一点,因为在我看来,很多当前的应用程序都想要/需要一个非常好的解决方案,它完美地展示了swizzling的使用。
+ (void) load
{
    if  (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
        // Running on iPad, nothing to change.
        return;
    }

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    BOOL tallDevice = (screenBounds.size.height > 480);
    if (!tallDevice) {
        // Running on a 320✕480 device, nothing to change.
        return;
    }

    method_exchangeImplementations(
        class_getClassMethod(self, @selector(imageNamed:)),
        class_getClassMethod(self, @selector(imageNamedH568:))
    );
}

// Note that calling +imageNamedH568: here is not a recursive call,
// since we have exchanged the method implementations for +imageNamed:
// and +imageNamedH568: above.
+ (UIImage*) imageNamedH568: (NSString*) imageName
{
    NSString *tallImageName = [imageName stringByAppendingString:@"-568h@2x"];
    NSString *tallImagePath = [[NSBundle mainBundle] pathForResource:tallImageName ofType:@"png"];
    if (tallImagePath != nil) {
        // Tall image found, let’s use it. We just have to pass the
        // image name without the @2x suffix to get the correct scale.
        imageName = [imageName stringByAppendingString:@"-568h"];
    }
    return [UIImage imageNamedH568:imageName];
}