How to use images asset catalog in cocoapod library for iOS

前端 未结 11 2396
粉色の甜心
粉色の甜心 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:22

    At least as of version 1.0.1 of Cocoapods, image asset catalogs are supported.

    In my Swift 4.2 code, I used:

    public static var GoogleIcon: UIImage {
        let bundle = Bundle(for: self)
        log.msg("bundle: \(bundle)")
        return UIImage(named: "GoogleIcon", in: bundle, compatibleWith: nil)!
    }
    

    In my pod spec, I used:

    s.resources = "SMCoreLib/Assets/*.xcassets"
    

    When I build using the simulator, the .car file does show up in the Framework:

    cd /Users//SMCoreLib.framework 
    ls
    Assets.car  Info.plist  SMCoreLib
    

提交回复
热议问题