使用xcassets中的组加载图像数组 [英] Load array of images using group in xcassets

查看:99
本文介绍了使用xcassets中的组加载图像数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xcassets层次结构,如下所示:

I have a xcassets hierarchy as follow:

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


我该如何(优雅地?):


How can I (elegantly?):

  • 获取"Set1"组中的组列表
  • 从特定组加载[UIImage]
  • get the list of group in the "Set1" group
  • load an [UIImage] from a specific group

所以我可以做类似〜

  1. 列出"Set1"中的所有文件夹
  2. 随机选择一个文件夹
  3. 将该文件夹的所有图像加载到[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)

推荐答案

您不能自检资产目录.因此,您不能向其提出诸如Set1包含哪些文件夹"或Birds包含哪些图像之类的问题.

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

如果您需要这种自省,请不要使用资产目录.使用嵌入到应用程序捆绑包顶层的文件夹引用.现在,您有了真实的文件夹和文件,并且可以浏览这些文件夹并使用普通的FileManager方法询问它们包含哪些图像文件.

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.

这篇关于使用xcassets中的组加载图像数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆