Asset Catalogs in resource bundles

前端 未结 3 1963
逝去的感伤
逝去的感伤 2021-02-02 11:13

I have a separate bundle of resources that ship with my framework. I want to put and use an asset catalog in that bundle. However UIImage imageNamed: says it uses the current ap

3条回答
  •  梦毁少年i
    2021-02-02 12:07

    There is a trick to make asset catalogs work with bundles: Set the resource bundle's deployment target to 6.1 (or below). Asset catalogs have only been around since 7.0, so Xcode won't actually build a .car file (compiled asset catalog) but copy the assets to the bundle directly, as documented here:

    Xcode 6 provides different functionality for asset catalogs depending on > the deployment target for your project:

    • For all projects, individual images can be loaded using set names.
    • For projects with a deployment target of at least iOS 7 or OS X 10.9, Xcode compiles your asset catalogs into a runtime binary file format that reduces the download time for your app.

    The caveat is that any additional information (slicing, rendering mode,...) is ignored, you only get the plain images. Although organisation via asset catalogs may be more convenient, I sense this could lead to some hard-to-find bugs/confusion...

    Edit: If you apply the trick described above, you will most-likely not get the App Slicing advantages introduced with iOS 9, as after building the app, there's no compiled asset catalog but only a bunch of plain images left, so Apple will not be able to strip resources automatically. This is only an assumption though.

提交回复
热议问题