可可触摸框架资产在App Project中不可见 [英] cocoa touch framework assets not visible in App Project

查看:79
本文介绍了可可触摸框架资产在App Project中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从早上开始,我一直在尝试创建可可触摸农艺,以将自包含的小部件放入其中,并允许以后我从事的任何应用程序使用它。

I've been trying since morning creating a cocoa touch farmework to put my self containing widget inside it, and to allow any app I'm working on to use it in the future.

我设法建立了项目并导出了.framework文件,但是现在没有显示所有资产。我的所有图像都在资产目录中。

I've managed to build the project and export .framework file, but all the assets are not showing now. all my Images are inside assets catalog.

由于.framework文件中包含(assets.car)文件,因此它们似乎已导出。

And they seem to be exported since the .framework file has (assets.car) file inside it.

我当前正在使用

UIImage* icon = [UIImage imageNamed:@"iconName"];

但是它总是返回null,任何想法吗?

But it always returns null, Any ideas ?

推荐答案

创建图像时,您可以提供框架捆绑包。在Swift 2中:

You can supply the framework bundle when creating an image. In Swift 2:

class func getMyImage() -> UIImage? {
    let bundle = NSBundle(forClass: self)
    return UIImage(named: "YourImageName", inBundle: bundle, compatibleWithTraitCollection: nil)
}

Swift 3:

class func getMyImage() -> UIImage? {
    let bundle = Bundle(for: type(of: self))
    return UIImage(named: "YourImageName", in: bundle, compatibleWith: nil)
}

这里是一个演示项目,其中包含带有图像的框架和使用该图像的应用。

Here is a demo project containing a framework with an image and an app that uses it.

https://github.com/marketplacer/AssetFrameworkDemo

这篇关于可可触摸框架资产在App Project中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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