どうも、ちょげ(@chogetarou)です。
画像であるImageのアスペクト比を設定する方法を紹介します。
方法

Imageのアスペクト比を設定するには、aspectRatio修飾子を使います。
まず、ImageにaspectRatio修飾子を付与します。
そして、aspectRatio修飾子を付与します。
aspectRatio修飾子の第1引数にアスペクト比を指定します。
Image("image")
.aspectRatio(ratio, contentMode: .fit) //第1引数にアスペクト比を指定
aspectRatio修飾子を付与することで、Imageのアスペクト比を設定することが出来ます。
使用例

struct ContentView: View {
var body: some View {
VStack {
Image("DogPhoto")
.resizable()
.aspectRatio(3 / 2, contentMode: .fit)
.padding()
}
}
}
コメント