如何在 Cocoa Touch 框架中加载图像?

How to load images in a Cocoa Touch framework?

我已经创建了 Cocoa Touch base 应用程序并尝试以编程方式加载图像。我已将我的图像放在捆绑资源中。然而,通过故事板加载图像,但无法以编程方式工作。图片不会显示。

我们正在创建用于其他项目的框架,因此在您的框架中您想要访问您的 frameWork 包,通过以下代码获取 frameWork 包。

func getBundle() -> Bundle? {
    var bundle: Bundle?
    if let urlString = Bundle.main.path(forResource: "YOUR_FRAMEWORK_BUNDLE_NAME", ofType: "framework", inDirectory: "Frameworks") {
        bundle = (Bundle(url: URL(fileURLWithPath: urlString)))
    }
        return bundle
}


let bundel = getBundle()

imageView.image = UIImage(named: "image.jpg", in: bundel, compatibleWith: nil)