资源包中的资产目录 [英] Asset Catalogs in resource bundles

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

问题描述

我的框架附带了一个单独的资源包。我想在该捆绑中放置和使用资产目录。然而UIImage imageNamed:说它使用当前的应用程序主包。如何从另一个包中的资产目录加载图像?

I have a separate bundle of resources that ship with my framework. I want to put and use an asset catalog in that bundle. However UIImage imageNamed: says it uses the current apps main bundle. How do I load an image from an asset catalog in a different bundle?

使用[bundle pathForResource:name ofType:@png]的技巧不起作用使用已编译的资产目录。我已经验证了Assets.car文件确实在包中并且它包含我的图像。

The trick of using [bundle pathForResource:name ofType:@"png"] doesn't work with the compiled asset catalog. I have verified that the Assets.car file is indeed in the bundle and it contains my images.

推荐答案

从iOS 8开始,您现在可以使用 [UIImage imageNamed:inBundle:compatibleWithTraitCollection: ] 从不同的包中按名称加载图像。例如,动态框架可以使用与主应用程序包分开的自己的资产目录。

As of iOS 8, you can now use [UIImage imageNamed:inBundle:compatibleWithTraitCollection:] to load images by name from a different bundle. For example, a dynamic framework can use its own asset catalog separate from the main app's bundle.

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

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