ios - 如何使用 Swift 从 Assets 中加载特定图像

标签 ios image swift size assets

<分区>

我是 Swift 的新手,我想从 Assets 中加载特殊图像。例如我有:

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 加载一个特定的图像,比如

self.GSquare = SKSpriteNode(imageNamed: "./Images.xcassets/green-square-Retina@2x.png")

这可能吗?

最佳答案

您不能直接使用@2x@3x 加载图片,系统会自动选择合适的图片,只需使用UIImage 指定名称即可:

UIImage(named: "green-square-Retina")

关于ios - 如何使用 Swift 从 Assets 中加载特定图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29356574/

相关文章:

ios - @available 属性不适用于 XCTest 类或方法

ios - 如何在 swift 中使用 cosmos 评级 Controller 显示半星评级?

ios - 是否可以在 UITextview 链接选择上设置清除颜色?

ios - 在 Firestore 中获取数据

ios - NSDate 在 CoreData 中被保存为时间戳

javascript - IE7-8 忽略有选择地忽略 jquery image .load() 和/或 .load 函数的内容

C++ Opencv - 通过套接字获取图像后的图像处理

php - 使用 imagick PHP 在 png 图像周围添加边框

ios - 从 Collection View 传递到 View Controller 的简单图像数据失败

ios - xcode 不会将最新文件复制到 .app(包内容)