SwiftUI 方面填充

Nik*_*Nik 3 ios swift swiftui

什么SwiftUI相当于UIImageView aspectFill选项?

当我做

Image(self.chat.thumbnailName)
.resizable()
.frame(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.width)
.clipped()
Run Code Online (Sandbox Code Playgroud)

(也尝试添加.aspectRatio(contentMode: .fill).aspectRatio(contentMode: .fit)

我仍然得到一个丑陋的扭曲图像:

在此处输入图片说明

Asp*_*eri 8

根据需要使用.scaledToFill.scaledToFit修饰符。所以在你的情况下

Image(self.chat.thumbnailName)
.resizable()
.scaledToFill()
.frame(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.width)
.clipped()
Run Code Online (Sandbox Code Playgroud)