How to use images asset catalog in cocoapod library for iOS

前端 未结 11 2420
粉色の甜心
粉色の甜心 2020-12-15 16:38

I have a cocoapod library which contains assets in 2 formats:

  • a .storyboard
  • XCode asset catalog .xcassets (with images)

my podsp

11条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 17:26

    Add your .xcassets file within the resources in your pod spec, and use the following UIImage init:

    extension UIImage {
        convenience init?(podAssetName: String) {
            let podBundle = Bundle(for: ConfettiView.self)
    
        /// A given class within your Pod framework
        guard let url = podBundle.url(forResource: "CryptoContribute",
                                      withExtension: "bundle") else {
            return nil
    
        }
    
        self.init(named: podAssetName,
                  in: Bundle(url: url),
                  compatibleWith: nil)
        }
     }
    

提交回复
热议问题