从Cocoapod的xcassets获取图像不起作用

时间:2016-03-28 21:35:22

标签: ios xcode swift cocoapods xcasset

我正在使用1Password Pod和GCast pod,它们都有xcassets文件以及他们希望您使用的资产。当我在IB中创建一个按钮并为其分配xcassets文件中的一个图像的名称时,会显示正确的图像但在运行时我得到的调试错误为:Could not load the "onepassword-button" image referenced from a nib in the bundle with identifier "com.myApp.App"

知道我需要做什么吗?感谢

1 个答案:

答案 0 :(得分:1)

我发现解决此问题的唯一方法是以编程方式指定图像,而不是在Interface Builder中指定:

let bundle = NSBundle(forClass: OnePasswordExtension.self)
let image = UIImage(named: "OnePasswordExtensionResources.bundle/onepassword-button", inBundle: bundle,
                    compatibleWithTraitCollection: nil)

请注意,您仍需要在UIImage初始化程序中指定资源包的完整路径,因为bundle值不是资源包本身,而是容器框架包。

相关问题