framework 图片资源 bundle

一重bundle可用:

extension UIImage {

    internal class func imageInBundle(named name: String, from bundle: String? = nil) -> UIImage? {

        if let bundleUrl = Bundle(for: XXXVideoPlayer.self).url(forResource: "XXXVideoPlayer", withExtension: "bundle") {

            let bundle = Bundle(url: bundleUrl)!

            let imageNew = UIImage(named: name, in: bundle, compatibleWith: nil)

            return imageNew

        }

        return nil

    }

}


多重bundle,建议不用

extension UIImage {

    internal class func imageInBundle(named name: String, from bundle: String? = nil) -> UIImage? {

        guard let searchUrl = Bundle(for: XXXVideoPlayer.self).url(forResource: bundle ?? "XXXVideoPlayer", withExtension: "bundle") else { return nil }

        guard let bundleUrl = Bundle(url: searchUrl)?.url(forResource: "JHKPlayerBundle", withExtension: "bundle") else { return nil }

        let image = UIImage(named: name, in: Bundle(url: bundleUrl), compatibleWith: nil)

        return image

    }

}

你可能感兴趣的:(framework 图片资源 bundle)