ios - UIButton images for iPad
问题描述
I need bigger button & image sizes for iPad devices compared to iPhone. Before Size classes, I used to have images ending as @2x~ipad to have different version for iPad. However, it is not clear if the same approach is applicable when using Size classes and Trait collections, or there is a better approach? Also, is iPad Pro 12.9 inch @3x or @2x? I see conflicting responses, but if it is @2x, how do we have bigger image size for iPad Pro?
解决方案
您将大小与分辨率混淆了。
如果你有一个UIImageView在150 x 150
points,并且你有MyPic.png
++ ,图像视图的框架将始终是MyPic@2x.png
points ,但会自动为设备选择合适的分辨率图像。请参阅https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/image-size-and-resolution/MyPic@3x.png
150 x 150
UIKit
如果您想要根据设备/视图大小为按钮和图像设置不同大小的框架,请使用特征变化、代码或基于百分比的约束。
同样,如果您有相同图像的MyPic.png
++MyPic@2x.png
文件,则无论帧大小MyPic@3x.png
如何,都将使用适当的分辨率图像。
使用资产目录处理图像时有很大的灵活性。例如:
您可以为 1x 2x 和 3x 添加不同分辨率的图像...您可以添加特定于 iPhone / iPad / 等的图像集。
编辑
附加示例。资产被命名为“RoundSwift256x256”。iPhone 有 3 种分辨率,iPad 有 2 种分辨率(没有 iPad 使用 @3x)——使用不同的颜色使其非常明显。
在 Storyboard 中,我添加了一个 imageView,将其图像设置为RoundSwift256x256
. 然后将助理编辑器设置为预览并选择 iPhone 8 和 iPad Pro 9.7"。如您所见,它使用我的 iPhone 图像为 iPhone 和我的 iPad 图像为 iPad。
推荐阅读
- apache-kafka - Kafka Streams:有人可以指出一个完全实现的将消息发送到 DLQ(死信队列)主题的 java 示例
- spring-boot - 无法打开通过 spring rest api 下载的文件
- flutter - 断言失败:第 4774 行第 14 行:'_dependents.isEmpty':不正确
- axapta - 在 Axapta 3.0 中使用代码页 UTF-8 保存文本文件
- python - 在 USB 端口上读取串行通信时接收空数据 - Raspberry Pi 3 型号 B+
- swift - 奇怪的模糊 SKShapeNode
- mysql - MySQL 一次查询中的多个计数,带大小写
- jenkins - 无法在从机上使用参数安排 jenkins 构建
- angular - 使用 HostListener 和 Directive 的 ionic 4 angular 8 验证适用于所有表单控件
- excel - 在两张纸之间匹配数据并复制到位置