xcode 图像集名称“xxx”被具有本地化资产目录 (.xcassets) 的多个图像集使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24554445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The image set name "xxx" is used by multiple image sets with localized Asset Catalog (.xcassets)
提问by Jean Lebrument
I would like to use one Images.xcassets directory for each language supported by my app.
我想为我的应用程序支持的每种语言使用一个 Images.xcassets 目录。
So in the finder I put one Images.xcassets directory in each .lproj directory
所以在查找器中,我在每个 .lproj 目录中放置了一个 Images.xcassets 目录
In xCode I have:
在 xCode 中,我有:
For both the english and french xcassets they have english and french checked in localization field in xCode.
对于英语和法语 xcasset,他们在 xCode 的本地化字段中检查了英语和法语。
But when I compile I've got warnings for all my images in the Asset Catalogs:
但是当我编译时,我在资产目录中收到了所有图像的警告:
The image set name "xxx" is used by multiple image sets
图像集名称“xxx”被多个图像集使用
How can I correct the error ?
我该如何纠正错误?
回答by mrodriguez
You can't have two images with the same name on xcassets.
xcassets 上不能有两个同名的图像。
I found this because i had one image with this name 'default.png' for iPad and other with the same name for iPhone inside of a file of xcassets. The reason for your warning is because of this. Two images with the same name.
我发现这个是因为我在 xcassets 文件中有一个名为“default.png”的 iPad 图像和另一个与 iPhone 同名的图像。你发出警告的原因是因为这个。两张同名的图片。
The solution is to have one image 'default.png' and inside configure the different devices that the image supports.
解决方案是使用一张图像“default.png”并在内部配置该图像支持的不同设备。
回答by odyth
According to several sources online you can't localize images inside asset catalogs. Most of them reference Xcode 5.1.1, however as of Xcode 6.1 it appears you still can't localize them. Its recommended to just remove the images from the asset catalogs and do it the old fashion way.
根据多个在线消息来源,您无法本地化资产目录中的图像。他们中的大多数都引用了 Xcode 5.1.1,但是从 Xcode 6.1 开始,您似乎仍然无法本地化它们。建议仅从资产目录中删除图像并以旧方式进行操作。
回答by Luke
I was doing something similar in wanting to swap out my app icons from different asset catalogs depending on whether I built debug, ad-hoc, or release. My solution was to not include the debug and ad-hoc catalogs in any targets, then write a run script in Swift to copy over those assets at runtime. Here's the script:
我正在做类似的事情,希望根据我是构建调试、临时还是发布,从不同的资产目录中换出我的应用程序图标。我的解决方案是不在任何目标中包含调试和临时目录,然后在 Swift 中编写一个运行脚本以在运行时复制这些资产。这是脚本:
import Foundation
struct CopyNonReleaseIcons: Script {
var usage: String {
return "When running a non-release (Debug or AdHoc) build, switches out the app icon to help" +
"differentiate between builds on the home screen.\n\n" +
"Usage: swift CopyNonReleaseIcons.swift <CONFIGURATION> <PRODUCT_NAME> <BUILD_PATH>"
}
var expectedNumberOfArguments = 3
func run(arguments arguments: [String]) {
let configuration = arguments[0]
let productName = arguments[1]
let buildPath = arguments[2]
if configuration == "Debug" || configuration == "AdHoc" {
copyIcons(buildName: configuration, productName: productName, buildPath: buildPath)
}
}
func copyIcons(buildName buildName: String, productName: String, buildPath: String) {
let sourcePath = "My App/Resources/Asset Catalogs/" + productName + "SpecificAssets-" + buildName + "Icons.xcassets/AppIcon.appiconset/"
var appName = "My App.app"
if (productName == "White Label") {
appName = "White Label.app"
}
shell(launchPath: "/bin/cp", arguments: ["-rf", sourcePath, buildPath + "/" + appName])
}
}
CopyNonReleaseIcons().run()