gpt4 book ai didi

swift - 在 ios Swift 中的 Images.xcassets 文件夹中的 Collection View 中显示图像

转载 作者:可可西里 更新时间:2023-11-01 02:15:27 39 4
gpt4 key购买 nike

我在 Images.xcassets 中有一个图像文件夹。我只想显示该特定文件夹中的所有图像,并将这些图像加载到 Collection View 中。我知道我将不得不编写这段代码来显示图像

imageView.image = UIImage(named: "Apple")

我将不得不运行一个 for 循环来显示 Collection View 中的所有图像。但是我不知道如何访问 Images.xcassets 文件夹中的所有图像

最佳答案

嗯,按照我的理解,Assets.xcassets文件夹里面的一个文件夹是没有意义的。如果有一个名为 JackApple 的文件夹,那么在 Jack 中你有 Apple。然后您尝试运行 imageView.image = UIImage(named: "Apple"),是的,这会起作用。你不需要 imageView.image = UIImage(named: "Jack/Apple")

因此,如果您只是将图像命名为 image1image2image3image4image5 然后你可以做类似的事情。

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/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com