I have an image from the Images.xcassets
folder and I want to load it into a UIImage
programmatically using swift. How can I do this? Anyone done this before? Please give me some code examples!
Asked
Active
Viewed 3.9k times
39
-
3let img : UIImage = UIImage(named: "here is the name of the image from Images.xcassets"); – Saurabh Prajapati Aug 22 '15 at 05:02
2 Answers
64
Here's my code:
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = UIImage(named: "Apple")
}
I created an image view and displayed an image inside it.
Enjoy coding!

Bright
- 5,699
- 2
- 50
- 72
0
You can also create a 'standard' color xcassets item and load it via:
UIColor(named: "--asset--name--here--")

Waxhaw
- 599
- 5
- 9