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!
- 3let img : UIImage = UIImage(named: "here is the name of the image from Images.xcassets");Saurabh Prajapati– Saurabh Prajapati2015-08-22 05:02:03 +00:00Commented Aug 22, 2015 at 5:02
Add a comment |
3 Answers
With Xcode 16 the .xcassets identifiers are autogenerated so you can:
UIImage(resource: .logo) Assuming that you have Image Set named logo in default bundle's Assets.xcassets
(Not exactly sure how it works internally as if you "jump to definition" of .logo you'll end up in Assets.xcassets with selected logo image set)