我正在使用 1Password Pod 和 GCast pod,它们都有 xcassets 文件,其中包含他们希望您使用的 Assets 。当我在 IB 中创建一个按钮并为其指定 xcassets 文件中其中一个图像的名称时,会显示正确的图像,但在运行时出现调试错误:Could not load the "onepassword-button "从带有标识符“com.myApp.App”的包中的 nib 引用的图像
知道我需要做什么吗?谢谢
最佳答案
我发现解决这个问题的唯一方法是以编程方式指定图像,而不是在 Interface Builder 中:
let bundle = NSBundle(forClass: OnePasswordExtension.self)
let image = UIImage(named: "OnePasswordExtensionResources.bundle/onepassword-button", inBundle: bundle,
compatibleWithTraitCollection: nil)
请注意,您仍然需要在 UIImage
初始化程序中指定资源包的完整路径,因为 bundle
值不是资源包本身,而是容器框架捆绑。
关于ios - 从 Cocoapod 的 xcassets 获取图像不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36271618/