iOS : How using different size image with the same name in Assets. xcassets 在不同设备或不同景观上运行时

标签 ios xcode

目的

我要让我的 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"

完成

  1. 我在 iPad 上运行它,显示 ImageView 的图像
  2. 我在 iPhone 上运行它,ImageView 的图像不显示。

最佳答案

感谢您的关注和评论。 该问题是由图像设置不正确引起的。 图片的assets.xcassets 是这样变化的。这样就成功了。 图片应该喜欢这些。

Image should set like here

关于iOS : How using different size image with the same name in Assets. xcassets 在不同设备或不同景观上运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43884477/

相关文章:

iphone - Objective-C RabbitMQ 客户端未接收消息

ios - 了解 performSegueWithIdentifier

ios - 如何动态获取IOS模拟器设备的UID,然后安装到那个设备中

ios - 如果在 iOS 中按下按钮,如何禁用它?

ios - 在包含文本的 UIlabel 周围绘制虚线边框

ios - 如何仅在三个边上设置 UITextField 边框/CALayer 边框 ios

Swift 3 - Bundle.main.path 在不同目录中具有相同的文件名

ios - 将两个Xcode项目合并到一个Build中

iphone - awakeFromNib 和局部变量问题

ios - UITableView 重新加载数据确实适用于 IOS 7,但适用于 IOS Simulator