ShurupuS
ShurupuS

Reputation: 2923

Name for the image in different iOS versions

is there a way to name the images/icons which I use in my app somehow to use different icons in ios6/7?

For example I try to use:

[email protected]
[email protected]

And I would like Xcode automatically use the first one when I launch the app in ios7 and the second one in ios6. Any help?

Upvotes: 0

Views: 55

Answers (1)

topes
topes

Reputation: 26

Apple doesn't offer support for that, but one workaround could be to use a category for UIImage with a method that loads the right version based on the OS version:

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

This way, the images would be named:

example.png
[email protected]
[email protected]

And you can instantiate the image this way:

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

Hope this helps

Upvotes: 1

Related Questions