具有多个目标和多个资产目录的Xcode项目 [英] Xcode project with multiple targets and multiple assets catalogs

查看:130
本文介绍了具有多个目标和多个资产目录的Xcode项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有两个目标的项目:目标A和目标B.此目标生成的应用程序相等"但皮肤不同(不同的颜色和图像)

I have a project with two targets: target A and target B. This targets generate app which are "equal" but whit different skins (different colors and images)

为此,该项目有两个资产目录,它们是相同的,但内部具有不同的图像.每个资产目录都分配给相应的目标.

For this, the project has two Asset Catalogs, which are identical but have different images insides. Each Asset catalog is assigned to the corresponding target.

这很好用,我可以生成两个应用程序,但是在编辑情节提要和分配图像时,我只能从第一个资产目录中看到图像.

This works perfectly and I can generate both applications, but while editing the Storyboards and assigning the images I can only see the images from the first Asset Catalog.

有没有办法查看或预览"具有不同目录的情节提要?

Is there any way to see or "preview" the storyboards with the different Catalogs?

推荐答案

我们可以有多个资产目录.

We can have multiple asset catalogs.

我们有一个字母"项目,在这个项目中,我们有三个目标-三个应用程序. A,B和C.

We are having ‘Alphabets’ project and in this project, we are having three targets - three applications. A, B and C.

现在默认值是主目录中的"Assets.xcassets".

Now default one is ‘Assets.xcassets’ which is in the main directory.

例如:我的项目/字母/资产.xcassets-所有目标

您还可以在层次结构中创建尽可能多的xcasset. 下面列出了一些示例.

You can create as many as xcassets in hierarchy also. Listed some examples below.

My Projects/Alphabets/One/A/1A.xcassets - A Target

My Projects/Alphabets/Two/B/2B.xcassets - B Target

My Projects/Alphabets/Three/C/3C.xcassets - C Target

向此xcasset添加任何资源时,请确保Xcode中显示的名称与添加后的实际图像名称相同.之后,您将可以使用图像名称方法来使用它.

if target == "A" {
   let imageView = UIImageView(image: UIImage(named: "a"))
}
if target == "B" {
  let imageView = UIImageView(image: UIImage(named: "b"))
}
if target == "C" {
  let imageView = UIImageView(image: UIImage(named: "c"))
}

请检查此处所附的屏幕截图.

Please check screenshots attached here.

这篇关于具有多个目标和多个资产目录的Xcode项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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