Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an UIImage in Swift

I simply would like to display an image which is part of the app. When executing the following code, my image is nil.

let image = UIImage(named: "back.png");

The "back.png" is stored in my "Images.xcassets" folder of my project.

How to load the image from within the app folders?

(Loading the Image from a path is working for me, but I do not know how to reference an image stored in the project itself)

like image 801
mcfly soft Avatar asked May 07 '15 08:05

mcfly soft


1 Answers

With the latest Xcode 8.3 its much easier to adding any image, Using Image Literal option.

Just select any image from assets.

let image = //type and select Image Literal option, and select image from as per below reference

enter image description here

like image 87
swiftBoy Avatar answered Nov 15 '22 05:11

swiftBoy