David Smith
David Smith

Reputation: 11

How to load images from Images.xcassets into a UIImage with swift

I have a images from the Images.xcassets folder and I want to load them into a UIImage programmatically using swift. The images are for a list so image 1 corresponds to list item 1. How can I do this?
Please give me some code examples!

Upvotes: 0

Views: 2158

Answers (2)

Lise
Lise

Reputation: 21

let image = UIImage(named: "img_xxx")

Upvotes: 2

Tim Bull
Tim Bull

Reputation: 2495

let image = UIImage(named: "nameOfImageInXCAssets")

I'm giving you the benefit of the doubt on this one, but this is a very straight forward read the manual case.

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/#//apple_ref/occ/clm/UIImage/imageNamed:

There's even a section called "Loading and Caching Images"

Upvotes: 2

Related Questions