目的
我要让我的 iOS 应用程序在不同的设备上运行,包括 iPhone 和 iPad。 我想使用相同的名称设置不同大小的 ImageView 图像,以适应不同的设备和景观。
我在做什么
1.针对不同的设备特性将图像导入Assets.xcassets。
apple program reference: Create asset variations for different device traits
xcodes 的 Assets.xcassets 中的图像具有不同的宽度或高度类设置。我将图像命名为“homeBackground”
像这样的图像:
[1]: /image/yXHk4.png
2。将 imageView 拖入 Interface Builder
3。设置 imageView 的属性:Interface Builder 中的图像作为图像的名称“homeBackground”
4。在 iPad 或 iPhone 中查看
使用 xcode 8.3。我可以预览场景。 我可以看到 imageView 的图像设置成功,当以 Ipad 或 iPhone 查看时
问题
在 xcode 中运行应用程序。我在模拟器中没有看到 imageView 有图像,我有以下问题:
Could not load the "homeBackground" image referenced from a nib in the bundle with identifier "BTBubblePop"
完成
- 我在 iPad 上运行它,显示 ImageView 的图像
- 我在 iPhone 上运行它,ImageView 的图像不显示。
最佳答案
感谢您的关注和评论。 该问题是由图像设置不正确引起的。 图片的assets.xcassets 是这样变化的。这样就成功了。 图片应该喜欢这些。
关于iOS : How using different size image with the same name in Assets. xcassets 在不同设备或不同景观上运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43884477/