Load image from CocoaPods resource bundle

后端 未结 7 2100
独厮守ぢ
独厮守ぢ 2021-02-02 11:48

I am creating a private library that includes resources that are referenced by components in the library. The library is shared with apps using CocoaPods. In the .podspec for

7条回答
  •  走了就别回头了
    2021-02-02 12:13

    For example Paramount

    podspec

    s.resource_bundle = {
        'Paramount' => ['Sources/Paramount.bundle/*.png']
    }
    

    swift

    public extension UIImage {
      static func make(name: String) -> UIImage? {
        let bundle = NSBundle(forClass: Paramount.Toolbar.self)
        return UIImage(named: "Paramount.bundle/\(name)", inBundle: bundle, compatibleWithTraitCollection: nil)
      }
    }
    

    Here Paramount.Toolbar.self can be any class in that framework

提交回复
热议问题