IOS静态框架,里面有资源 [英] IOS Static Framework with resources inside

查看:20
本文介绍了IOS静态框架,里面有资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个框架来保存我在项目中使用的一些通用代码.我找到了在线教程并设法创建了一个框架,但我仍然有一个与资源(xib、图像等)相关的问题.

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).

假设我有一个 MainViewController.xib,它有一个使用 test.pngUIImageView.所有这些都在我的框架包中.

Let's say I have a MainViewController.xib which has a UIImageView using a test.png. All these are in my framework package.

当我在另一个项目中使用该框架时,我将其添加到复制捆绑资源"构建阶段.问题是 xib 只能使用 dummy.framework/Resources/MainViewController.xib 之类的路径访问,而里面的 UIImageView 无法加载 test.png.

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.

UIImageView 似乎会尝试从包的根目录加载 png,而不是从也存储 xib 的相对文件夹中加载.

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?

推荐答案

简答:你不能.

当您编译应用程序时,会使用主"项目的资源生成捆绑包,忽略链接框架中的资源.这包括图像、xib、plist 等(任何非源文件)

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屋!

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