0

有没有办法命名我在我的应用程序中使用的图像/图标以某种方式在 ios6/7 中使用不同的图标?

例如我尝试使用:

bar_item-ios7@2x.png
bar_item@2x.png

我希望 Xcode 在我在 ios7 中启动应用程序时自动使用第一个,在 ios6 中启动第二个。有什么帮助吗?

4

1 回答 1

1

Apple 不提供对此的支持,但一种解决方法可能是使用 UIImage 的类别以及根据操作系统版本加载正确版本的方法:

+(UIImage)imageNamed2:(NSString *)imageName{
    NSString *finalImageName;
    if([[UIDevice currentDevice].systemVersion floatValue] >= 7){
        finalImageName = [NSString stringWithFormat:@"ios7-%@",imageName];
    }else{
        finalImageName = imageName;
    }
    return [self imageNamed:finalImageName];
}

这样,图像将被命名为:

example.png
example@2x.png
ios7-example@2x.png

您可以通过这种方式实例化图像:

[UIImage imageNamed2:@"example.png"];

希望这可以帮助

于 2013-11-11T06:14:41.563 回答