【发布时间】:2020-10-03 09:32:44
【问题描述】:
当我在 HStack 中并试图在我的 Text 和 Textfield 视图之间创建空间时,我似乎无法让 Spacer() 函数工作。 Spacer 用于分隔视图的其他区域,但每当我尝试在这两个元素之间分隔时,它都不起作用。
这是我正在使用的代码:
VStack(alignment: .leading, spacing: 0) {
Rectangle()
.frame(height: 2, alignment: .top)
.foregroundColor(Color("grey2"))
Text("Tickets")
.kerning(0.5)
.scaledFont(name: "Gotham Medium", size: 18)
.foregroundColor(Color("grey4"))
.padding(.horizontal)
.padding(.bottom, 3)
.padding(.top, 35)
Rectangle()
.frame(height: 2, alignment: .top)
.foregroundColor(Color("grey2"))
HStack {
Text("Ticket URL")
.kerning(0.5)
.scaledFont(name: "Gotham Book", size: 16)
.foregroundColor(Color("spaceblack"))
Spacer()
TextField("Enter URL", text: $url)
}
.background(Color.blue)
.padding()
Rectangle()
.frame(height: 2, alignment: .top)
.foregroundColor(Color("grey2"))
}
.frame(maxWidth: .infinity)
.background(Color.red)
【问题讨论】:
-
TextField实际上与 Spacer 一样消耗所有可用宽度。那么你想达到什么目标呢?
标签: swiftui