Reputation: 1205
I have a Folder of Images in Images.xcassets. I want to display all the images from only that particular folder and load those images in a collection view. I know i will have to write this code to display the images
imageView.image = UIImage(named: "Apple")
I will have to run a for loop to display all the images in the collection view. But i do not know how to access all the images from the Images.xcassets folder
Upvotes: 2
Views: 1473
Reputation: 1873
Well, according to my understandings, a folder inside the Assets.xcassets
folder means nothing. If there is a folder called Jack
, Apple
then inside Jack
you have Apple
. Then you try running imageView.image = UIImage(named: "Apple")
, yes this will work. You don't need imageView.image = UIImage(named: "Jack/Apple")
.
So if you just name your images something like image1
, image2
, image3
, image4
, image5
then you can do something like.
for index in 0 ..< 5 {
imageView.image = UIImage(named: String(format: "image%i", index))
}
It doesn't matter where the images are located in the files.
Upvotes: 1