如何使用Swift从资产加载特定图像 [英] How to load specific image from assets with Swift
本文介绍了如何使用Swift从资产加载特定图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Swift的新手,我想从资产中加载特殊图像。例如我有:
I'm new to Swift and I want to load a special image from assets. For example I have:
image 1 for iphone 4s = green-square@2x.png
image 2 for iphone 5/5s = green-square-Retina@2x.png
image 3 for iphone 6s = green-square@3x.png
我想为iphone 6加载一个特定的图像,如
and I want to load for iphone 6 a specific image like
self.GSquare = SKSpriteNode(imageNamed: "./Images.xcassets/green-square-Retina@2x.png")
是否有可能?
推荐答案
您不应该直接使用 @ 2x $ c $加载图像c>或
@ 3x
,系统自动选择合适的图像,你只需要指定名称,如 UIImage(名称:green-square-Retina )
You shouldn't load images directly with @2x
or @3x
, system selects appropriate image automatically, you only need to specify the name, like UIImage(named: "green-square-Retina")
这篇关于如何使用Swift从资产加载特定图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文