I need to load localized images in my iOS app, but also have to take into account that they might need to be the ...@2x
kind. How can I do this?
views:
54answers:
2
+1
A:
NSLocalizedString should do the trick. See Localizing String Resources.
UIImage *img = [UIImage imageNamed:NSLocalizedString(@"TestImage",@"")];
catlan
2010-09-24 14:31:53
No, I mean the image is localized, not the name. I have a resource in `en.lproj` and one in `es.lproj`, etc.
Alexsander Akers
2010-09-24 16:49:42
I'm not sure how to simple load the image when it's in a *.lproj folder. Using the method above you would have all the image in your resource folder with a suffix like TestImage-es.png and map them in the string file.
catlan
2010-09-24 19:34:16
A:
Use the methods of NSBundle to fetch the path of the image and then load it using UIImage's imageWithContentsOfFile method. I added a method to UIImage for this, like:
@implementation UIImage (UIImageAdditions)
+ (UIImage*)localizedImageNamed:(NSString*)name
{
NSString* path = [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
return [self imageWithContentsOfFile:path];
}
@end
Peyman
2010-10-21 21:43:02