Reputation: 20068
I have tried this:
self.relationshipImage.image = UIImage(named: "pic1")
self.relationshipImage.image = UIImage(named: "pic2", inBundle: NSBundle.mainBundle(), compatibleWithTraitCollection: nil)
Where pic1
and pic2
are .pdf
files. I can select them in the storyboard, but not programmatically.
Any idea how to do this ?
Upvotes: 2
Views: 1503
Reputation: 12617
Depending on where your asset catalog is being stored, you may have to explicitly point to its enclosing bundle. You try this code:
let bundle = NSBundle(forClass: self.classForCoder)
let image = UIImage(named: "pic1", inBundle: bundle, compatibleWithTraitCollection: nil)
This will look for the image in the same bundle as the class where you are requesting the image.
Upvotes: 4