无法在捆绑上的xcassets中加载图像 [英] Impossible to load an image in xcassets on bundle
问题描述
我需要在静态库中包含图像。
我创建了一个捆绑并插入到我的图像中,问题是如果我将图像直接包含在捆绑包中似乎可行,但如果我放入xcassets文件则停止工作。
I need to include images in a static library. I created a bundle and inserted in my images, the problem is that it seems to work if I include the images directly in the bundle, but stops working if I put in a xcassets file.
我跟随了很多指南并在这个网站上搜索了一个解决方案。
最流行的解决方案是插入以下代码行:
I followed many guides and searched for a solution on this site. The most popular solution is to insert this line of code:
[UIImage imageNamed:@"MyBundle.bundle/imageName"]
但似乎对我不起作用
任何想法?
推荐答案
有两种方法可以解决这个问题,
There are two ways to solve this,
如果您的应用仍然支持iOs 7,您可以使用以下类别:
https:// gist。 github.com/serluca/e4f6a47ffbc19fccc63e
If your app is still supporting iOs 7, you can use this category: https://gist.github.com/serluca/e4f6a47ffbc19fccc63e
否则,从iOs 8开始,Apple添加了一种方法来执行此操作:
+ imageNamed:inBundle:compatibleWithTraitCollection:
已定义 here
Otherwise, starting from iOs 8 Apple added a way to do this using:
+ imageNamed:inBundle:compatibleWithTraitCollection:
defined here
这篇关于无法在捆绑上的xcassets中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!