我正在创建一个广告连播并且我有一个我想使用的图像 Assets 目录。 在我的 .podspec 文件中,我将其设置如下:
s.resource_bundles = {
'MyPodResources' => ['*.xcassets']
}
并且 Images.xcassets 位于 pod 的根目录中。
当我尝试使用 imageNamed()
加载图像时,它就是不工作。我没有收到错误或警告,但没有显示图像。
这是有趣的部分 - 如果我尝试在示例应用程序的 Main.storyboard 中添加图像,我可以选择该图像并且它在 Interface Builder 中显示良好。但是,当我运行示例应用程序时,图像不可见。
我已经查看了 GH 上的所有问题,但仍然找不到解决此问题的方法...这是 Xcode 7/iOS 9 问题吗?
谢谢!
最佳答案
最后我写了一个UIImage
的扩展放在pod目录下。它看起来像这样:
class func bundledImage(named: String) -> UIImage? {
let image = UIImage(named: named)
if image == nil {
return UIImage(named: named, inBundle: NSBundle(forClass: MyBasePodClass.classForCoder()), compatibleWithTraitCollection: nil)
} // Replace MyBasePodClass with yours
return image
}
我正在使用它:
imageView.image = UIImage.bundledImage("icon-grid")
就是这样,希望有人觉得这有用!
关于ios - 无法在 CocoaPods 中从 .xcasset 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33063233/