【发布时间】:2014-08-24 14:54:37
【问题描述】:
我想为我的应用支持的每种语言使用一个 Images.xcassets 目录。
所以在查找器中,我在每个 .lproj 目录中放置了一个 Images.xcassets 目录
在 xCode 中我有:
对于英语和法语 xcasset,他们在 xCode 的本地化字段中检查了英语和法语。
但是当我编译时,我的资产目录中的所有图像都会收到警告:
图像集名称“xxx”被多个图像集使用
我该如何纠正错误?
【问题讨论】:
我想为我的应用支持的每种语言使用一个 Images.xcassets 目录。
所以在查找器中,我在每个 .lproj 目录中放置了一个 Images.xcassets 目录
在 xCode 中我有:
对于英语和法语 xcasset,他们在 xCode 的本地化字段中检查了英语和法语。
但是当我编译时,我的资产目录中的所有图像都会收到警告:
图像集名称“xxx”被多个图像集使用
我该如何纠正错误?
【问题讨论】:
xcasset 上不能有两个同名的图像。
我发现这个是因为我在 xcassets 文件中有一张用于 iPad 的名称为“default.png”的图像,而另一张用于 iPhone 的名称相同。你警告的原因是因为这个。两个具有相同名称的图像。
解决方案是拥有一个图像“default.png”并在内部配置图像支持的不同设备。
【讨论】:
根据几个在线来源,您无法在资产目录中本地化图像。他们中的大多数都引用了 Xcode 5.1.1,但是从 Xcode 6.1 开始,您似乎仍然无法本地化它们。建议仅从资产目录中删除图像并以旧方式进行。
【讨论】:
我正在做类似的事情,希望根据我是构建调试、临时还是发布来从不同的资产目录中交换我的应用程序图标。我的解决方案是不在任何目标中包含调试和临时目录,然后在 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()
【讨论】: