如何在Images.xcassets中本地化图像? [英] How to localize the images in Images.xcassets?

查看:141
本文介绍了如何在Images.xcassets中本地化图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用 Localize ... 这样在文件检查器中本地化图像:

We can localize an image in the File Inspector using Localize... like this:

然后我们可以得到这个:

Then we can get this:

但是现在,我使用Images.xcassets来管理我的iOS项目中的图像,我应该如何在Images.xcassets中本地化这些图像?

But now, I use Images.xcassets to manage my images in my iOS project, how should I localize these images in Images.xcassets?

推荐答案

虽然(显然)目前还没有一种直接显式本地化xcassets文件的方法,但可以使用Localizable.strings文件本地化要拉取的资产的名称。例如,假设您对游戏的主菜单有一个图形徽标处理,需要进行本地化。您可以使用不同的名称将本地化徽标处理放在assets文件中,将名称添加到Localizable.strings文件中,然后使用以下代码获取相应的图像:

While there's (apparently) not currently a way to explicitly localize the xcassets file directly, you could localize the name of the asset to pull using your Localizable.strings file. For instance, say you have a graphic logo treatment for the main menu of a game that needs to be localized. You could put the localized logo treatments in the assets file with different names, add the names to your Localizable.strings file, and then fetch the appropriate image with code like this:

UIImage *img = [UIImage imageNamed:NSLocalizedString(@"MAIN_MENU_IMAGE", nil)];

这篇关于如何在Images.xcassets中本地化图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆