I'm new to Swift and I want to load a special image from assets. For example I have:
image 1 for iphone 4s = [email protected] image 2 for iphone 5/5s = [email protected] image 3 for iphone 6s = [email protected]
and I want to load for iphone 6 a specific image like
self.GSquare = SKSpriteNode(imageNamed: "./Images.xcassets/[email protected]")
Is it possible?
Drag and drop image onto Xcode's assets catalog. Or, click on a plus button at the very bottom of the Assets navigator view and then select “New Image Set”. After that, drag and drop an image into the newly create Image Set, placing it at appropriate 1x, 2x or 3x slot.
Use PHAsset class methods to fetch the assets you're interested in. To prepare images for those assets, call the startCachingImagesForAssets:targetSize:contentMode:options: method with the target size, content mode, and options you plan to use when later requesting images for each individual asset.
Select New > Project... from Xcode's File menu and choose the Single View App template from the iOS > Application section. Name the project Images and set User Interface to Storyboard. Leave the checkboxes at the bottom unchecked. Tell Xcode where you would like to save the project and click the Create button.
You cannot load images directly with @2x
or @3x
, system selects appropriate image automatically, just specify the name using UIImage
:
UIImage(named: "green-square-Retina")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With