I have an Image Set called "SmileyFace" which contains a 1x, 2x and 3x image sizes. I want to copy to pasteboard a specific size from the image set. How do I reference the 1x, 2x or 3x programmatically in the code below?
let image = UIImage(named: "SmileyFace" )
let image2 = UIImagePNGRepresentation( image )
UIPasteboard.generalPasteboard().setData(image2, forPasteboardType: "public.png")
This code copies the 1x. I want to copy the 2x image.
I have not found anything in the Apple Documentation that seems to reference this.
You can use
imageAsset.registerImage()
method:You can register 2x image for all the scales.
However, I dont think it is good idea to access an image with specific resolution. The idea if 1x, 2x and 3x image set is to let the system to decide which image should be loaded. If you really want to, you might change the name of your 1x, 2x and 3x images to SmileyFace-Small, SmileyFace-regular, SmileyFace-large.
UPDATE:
func imageWithTraitCollection(traitCollection: UITraitCollection) -> UIImage
can reference an image with specific scale: