简体   繁体   中英

Xcode project with multiple targets and multiple assets catalogs

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.

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

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

For ex: My Projects/Alphabets/Assets.xcassets - All Targets

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 

When you are adding any resource to this xcassets, make sure that the name which is displayed in Xcode and the actual image name when you have added it are same. After that you will be able to user it using the image name method.

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.

第一步

第二步

第三步

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM