Load array of images using group in xcassets [duplicate]

余生颓废 提交于 2019-12-21 22:08:21

问题


I have a xcassets hierarchy as follow:

xcasset
| Set1 (folder)
| | Birds (folder)
| | | image1
| | | image2
| | | image3
| | | image4
| | Foo (folder)
| | Bar (folder)

How can I (elegantly?):

  • get the list of group in the "Set1" group
  • load an [UIImage] from a specific group

So I could do something that looks like ~

  1. list all folders in "Set1"
  2. pick one folder randomly
  3. load all images of that folder in a [UIImage]

The cool thing here would be to be able to update sets without having to change anything in the code (and not having to set a specific name policy)


回答1:


You cannot introspect an asset catalog. So you cannot ask it questions like what "folders" Set1 contains, or what images Birds contains.

If you need that sort of introspection, don't use an asset catalog. Use folder references embedded into the top level of your app bundle. Now you have real folders and files, and you can navigate the folders and ask what image files they contain using ordinary FileManager methods.



来源:https://stackoverflow.com/questions/48720250/load-array-of-images-using-group-in-xcassets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!