Luca Torella
Luca Torella

Reputation: 8214

imageNamed and localization issue

I've localized my images via Xcode, and all the images are in the proper lproj folder.

However, when I use imageNamed I don't get the correct image, but I keep getting the default image even if I change language.

_myImageView.image = [UIImage imageNamed:@"image_name"];

Upvotes: 0

Views: 376

Answers (2)

Nikos M.
Nikos M.

Reputation: 13783

Instead of:

_myImageView.image = [UIImage imageNamed:@"image_name"];

use:

NSString *imageName = NSLocalizedString(@"image_name", @"image_name");
_myImageView.image = [UIImage imageNamed:imageName];

and localize your image names using the Localizable.strings files like any other resource in your project.

Upvotes: 0

Luca Torella
Luca Torella

Reputation: 8214

This kind of issue made me waste some time, but then I realized it was a false issue and I hope to save you precious time.

If you switch language and the images are not in the new language, that's because of cached images. The documentation is straightforward:

This method looks in the system caches for an image object with the specified name and returns that object if it exists

Hence, when you switch language, and you ask for the same name to the cache, you'll get the old image! That's it. :)

Upvotes: 2

Related Questions