加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – iOS:管理本地化图像

发布时间:2020-12-16 09:40:38 所属栏目:百科 来源:网络整理
导读:我为iPhone App提供了2套本地化图像.我应该如何放置图像?我怎样才能加载到应用程序中? 文件夹结构如下: For English version:/MyApp/en.lproj/Localizable.strings,InfoPList.strings/MyApp/en.lproj/*.png (images)For Traditional Chinese version:/MyA
我为iPhone App提供了2套本地化图像.我应该如何放置图像?我怎样才能加载到应用程序中?

文件夹结构如下:

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)

我该如何解决?

解决方法

为什么你自己获得语言包?您可以像这样本地化图像文件名:

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

并且在Localizable.strings文件中只映射该图像名称(假设日语是您的默认语言):

@"myimage_jp" = @"myimage_cn"

当然,你必须在资源中有2个版本的图像(myimage_jp和myimage_cn)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读