2012-02-22 39 views
3

我有2套iPhone应用程序本地化图像。我应该如何放置图像?我怎样才能加载到应用程序?iOS:管理本地化图像

的文件夹结构如下:

For English version: 
/MyApp/en.lproj/Localizable.strings , InfoPList.strings 
/MyApp/en.lproj/*.png (images) 

For Traditional Chinese version: 
/MyApp/zh-Hant.lproj/Localizable.strings , InfoPList.strings 
/MyApp/Resources/*.png (images) 

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
NSString *locale = [[defaults objectForKey:@"AppleLanguages"] objectAtIndex:0]; 
NSString* path= [[NSBundle mainBundle] pathForResource:locale ofType:@"lproj"]; 
NSBundle* languageBundle = [NSBundle bundleWithPath:path]; 
SomeViewController *vc = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:languageBundle]; 

我想用相同的文件名两个组图像,使其自动加载。可能吗?

现在我遇到一个问题。在调试控制台中,它说:

NSBundle </Users/SomeUser/Library/Application Support/iPhone Simulator/5.0/Applications/1DC22505-1E78-4B5E-A794-DBF72DC786AE/MyApp.app/zh-Hant.lproj> (not yet loaded) 

我该如何解决它?

回答

7

为什么你的语言捆绑自己吗?你可以只定位图像文件名像这样:

NSString *imageName = NSLocalizedString(@"myimage_jp", @"localized image"); 
UIImage *image = [UIImage imageNamed:imageName]; 

而在Localizable.strings文件只是映射的是图像的名字,像这样(假设日本是默认的语言):

@"myimage_jp" = @"myimage_cn" 

当然你就必须有2个版本的资源(myimage_jpmyimage_cn

+0

哪里应该把图像的图像吗?相同的文件夹(全部在'/ MyApp/Resources /'或者他们的'.lproj')? – Raptor 2012-02-22 06:54:16

+1

在Resources文件夹中 – 2012-02-22 06:54:47

+0

如果我在视图控制器的初始化中将bundle设置为'nil',则在重新启动应用程序后,图像效果不错。有什么方法可以在不重新启动的情况下更改应用图片吗? – Raptor 2012-02-22 07:40:32