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

Mar*_*rke 5 xcode ios cocoapods xcasset swift

我正在使用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"

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

Max*_*tov 1

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

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

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