1.6_如何调整图像视图的填充模式

1.6_ba_xian_tai SwiftUI 的 Image 视图能够以不同的方式进行缩放,就像 UIImageViewcontent mode 一样。

1.默认

默认情况下,图像视图会根据其内容自动调整大小,这可能会使它们超出屏幕范围。

Image("ba_xian_tai")

效果预览: 1.6_the_default_content_mode

如果添加 resizable() 修饰符,则图像将自动调整大小,以填充所有可用空间:

Image("ba_xian_tai")
    .resizable()

效果预览: 1.6_resizable_image 然而,这也可能导致图像的原始纵横比失真,因为它将在所有维度上被拉伸任意量,以使其填充空间。

2. .fill.fit

如果要保持其纵横比,应使用 .fill.fit添加一个aspectRatio()修饰符,如下所示:

2.1 fill

Image("ba_xian_tai")
    .resizable()
    .aspectRatio(contentMode: .fill)

效果预览: 1.6_fill_content_mode

2.2 fit

Image("ba_xian_tai")
    .resizable()
    .aspectRatio(contentMode: .fit)

效果预览: 1.6_fit_content_mode

Avatar
M X
Mobile, Front-End Developer

My research interests include swift developing, python developing and go developing.

Related

Next
Previous
comments powered by Disqus