どうも、ちょげ(@chogetarou)です。
Rectangleビューにアスペクト比を設定する方法を紹介します。
方法

Rectangleにアスペクト比を設定するには、aspectRatio修飾子を使います。
まず、RectangleにaspectRatio修飾子を付与します。
そして、aspectRatio修飾子の第1引数にアスペクト比(横幅 ÷ 高さ)、引数「contentMode」に「.fit」を指定します。。
Rectangle()
.aspectRatio(アスペクト比, contentMode: .fit)
aspectRatio修飾子を使うことで、Rectangleにアスペクト比を設定することが出来ます。
使用例

struct ContentView: View {
var body: some View {
VStack {
Rectangle()
.aspectRatio(1.5, contentMode: .fit)
}
}
}
コメント