如何从NSBundle中的Assets.car(xcassets的编译版本)加载图像? (不使用CocoaPods) [英] How can I load an image from Assets.car (compiled version of xcassets) within an NSBundle? (without using CocoaPods)

查看:2254
本文介绍了如何从NSBundle中的Assets.car(xcassets的编译版本)加载图像? (不使用CocoaPods)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们收到以下类型的错误消息:

We're getting these kind of error messages:

无法加载带有标识符com.company的包中nib引用的iconStatus图像。 OurResourceBundle。

Could not load the "iconStatus" image referenced from a nib in the bundle with identifier "com.company.OurResourceBundle".

基本上,我们在xcassets文件夹中放置了一堆图像(适用于非捆绑加载的情况)。 xcassets和nib文件打包到资源包中。

Basically, we put a bunch of images in the xcassets folder ( which works for non-bundle loaded cases ). The xcassets and nib files are packed into a resource bundle.

当应用程序启动时,


  1. uibmageview在nib文件中无法加载任何带有上述错误消息的图像。

  2. [UIImage imageNamed:@OurResourceBundle.bundle / iconStatus]返回nil

问题与如何从NSBundle中的Assets.car(xcassets的编译版本)加载图像?,但我们不使用CocoaPods。

The question is related to "How can I load an image from Assets.car (compiled version of xcassets) within an NSBundle?", but we don't use CocoaPods.

推荐答案

在iOS 7中,除了Xcode编译成主包的文件之外,不能从任何.car文件加载图像。这是由Apple开发人员在 https://devforums.apple.com/message/968859#968859上确认的

In iOS 7 it is not possible to load images from any .car file aside from the one that Xcode compiles into the main bundle. This was confirmed by an Apple Developer at https://devforums.apple.com/message/968859#968859:


不幸的是,除了Xcode编译成主捆绑的文件外,无法从任何汽车文件加载图像,因为+ imageNamed:不接受捆绑参数,这是需要这样做的(即使那时它只能在一个捆绑中打开一个资产目录)。

Unfortunately it is not possible to load images from any car file aside from the one that Xcode compiles into your main bundle, as +imageNamed: does not accept a bundle parameter, which is what is needed to do so (and even then it would only be able to open a single asset catalog in a single bundle).

在iOS 8中,有一种新方法似乎可以满足您的需求:

In iOS 8 there is a new method that appears to do what you want:

+ (UIImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle
    compatibleWithTraitCollection:(UITraitCollection *)traitCollection

这篇关于如何从NSBundle中的Assets.car(xcassets的编译版本)加载图像? (不使用CocoaPods)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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