带有资源的IOS静态框架 [英] IOS Static Framework with resources inside
问题描述
我正在尝试创建一个框架,以保留我在项目中使用的一些常见代码。
我找到了在线教程,并设法创建了一个框架,但我仍然遇到与资源(xibs,图像等)相关的一个问题。
假设我有一个 MainViewController.xib
,它有一个 UIImageView
使用 test.png
。所有这些都在我的框架包中。
当我在另一个项目中使用框架时,我将它添加到Copy Bundle Resources构建阶段。问题是xib只能使用像 dummy.framework / Resources / MainViewController.xib
和 UIImageView
里面无法加载 test.png
。
看起来UIImageView会尝试从bundle的根目录加载png,而不是从xib也存储在其中的相关文件夹加载png。
有没有人设法创建一个包含代码和资源的框架,并将它用在另一个项目中?
当你编译应用程序时,这个包是用main项目的资源生成的,忽略资源在链接的框架。这包括图像,xib的,plist的等等(任何不是源文件)
你需要做的是将这些资源添加到你的主项目,以便它们可用于应用程序内部,而不是最快乐的方式,但它可以工作。
I'm trying to create a framework that keeps some common code I use around in my projects. I found online tutorials and managed to create a framework but I still have one problem related to resources (xibs, images, etc).
Let's say I have a MainViewController.xib
which has a UIImageView
using a test.png
. All these are in my framework package.
When I use the framework in another project, I add it to the "Copy Bundle Resources" build phase. The problem is that the xib is only accessible using a path like dummy.framework/Resources/MainViewController.xib
and the UIImageView
inside can't load test.png
.
It seems that the UIImageView will try to load the png from the root of the bundle, and not from the relative folder where the xib is also stored.
Has anybody managed to create a framework with code and resources and use it in another project?
Short answer: you can't.
When you compile the app, the bundle is generated with the resources of the "main" project, ignoring the resources in linked frameworks. This includes images, xib's, plist's, etc. (anything that isn't a source file)
What you need to do is add those resources to your main project so that they are available for use inside your application, not the happiest way around it but it'll work.
这篇关于带有资源的IOS静态框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!