参照:
Making fine adjustments to a view’s position | Apple Developer Documentation
概要:
- position、offsetどちらもビューの位置を決めるために使われる
- positionは親ビューが予め決めた子ビューの所定位置を上書きし、offsetは所定位置からの位置を指定する
サンプル:
①ZStack

ZStack (){
Text("TextA")
.background(Color.blue)
.position(x:0, y:0)
Text("TextB")
.background(Color.yellow)
.offset(x:0, y:0)
Text("TextC")
.background(Color.green)
.position(x:300, y:0)
}
.background(Color.red)
.frame(width:300, height:300)
②VStack

VStack (){
Text("TextA")
.background(Color.blue)
.position(x:0, y:0)
.frame(height: 100)
.border(.cyan,width:3)
Text("TextB")
.background(Color.yellow)
.offset(x:100, y:0)
.frame(height: 100)
.border(.white,width:3)
Text("TextC")
.background(Color.green)
.position(x:0, y:0)
.frame(height: 100)
.border(.brown,width:3)
}
.background(Color.red)
.frame(width:300, height:300)