我在 Images.xcassets 中有一个图像文件夹。我只想显示该特定文件夹中的所有图像,并将这些图像加载到 Collection View 中。我知道我将不得不编写这段代码来显示图像
imageView.image = UIImage(named: "Apple")
我将不得不运行一个 for 循环来显示 Collection View 中的所有图像。但是我不知道如何访问 Images.xcassets 文件夹中的所有图像
最佳答案
嗯,按照我的理解,Assets.xcassets
文件夹里面的一个文件夹是没有意义的。如果有一个名为 Jack
、Apple
的文件夹,那么在 Jack
中你有 Apple
。然后您尝试运行 imageView.image = UIImage(named: "Apple")
,是的,这会起作用。你不需要 imageView.image = UIImage(named: "Jack/Apple")
。
因此,如果您只是将图像命名为 image1
、image2
、image3
、image4
、image5
然后你可以做类似的事情。
for index in 0 ..< 5 {
imageView.image = UIImage(named: String(format: "image%i", index))
}
图像在文件中的位置并不重要。
关于swift - 在 ios Swift 中的 Images.xcassets 文件夹中的 Collection View 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39096055/