本文介绍了如何从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

问题与,但我们不使用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开发人员在:

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:

在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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:44
查看更多