【问题标题】:Getting images from Cocoapod's xcassets doesn't work从 Cocoapod 的 xcassets 获取图像不起作用
【发布时间】:2016-07-16 06:14:20
【问题描述】:

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

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

【问题讨论】:

    标签: ios xcode swift cocoapods xcasset


    【解决方案1】:

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

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

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

    【讨论】:

    猜你喜欢
    • 2014-04-16
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    相关资源
    最近更新 更多