我想在視圖的頂部中心繪制一個矩形 .. 但我不明白為什么使用這個簡單的代碼,當我應用填充時矩形會向右移動..
struct StartContent: View {
@ObservedObject var dm : DataManager
@Binding var user : UserModel?
var body: some View {
GeometryReader{ geo in
VStack(alignment: .trailing, spacing: 10) {
RoundedRectangle(cornerRadius: 20)
.stroke(Color.primary, lineWidth: 2)
.frame(width: geo.size.width, height: 200)
.padding(.horizontal)
}
}
}
}
// 看圖:

我希望我的矩形保持在視圖的中心...
謝謝..
uj5u.com熱心網友回復:
在幀之前設定水平填充。
RoundedRectangle(cornerRadius: 20)
.stroke(Color.primary, lineWidth: 2)
.padding(.horizontal)// << Here
.frame(width: geo.size.width, height: 200)
或將大小設定為VStack。
VStack(alignment: .trailing, spacing: 10) {
RoundedRectangle(cornerRadius: 20)
.stroke(Color.primary, lineWidth: 2)
.frame(width: geo.size.width, height: 200)
.padding(.horizontal)
}.frame(width: geo.size.width, height: geo.size.height) // <<=== Here
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/399866.html
