我尝试在SwiftUI
中为iOS创建一个View,并使用矩形作为Stacks周围的框架,但是我无法缩小Text
和HStack
框架之间的空间。
详细来说:我使用的是VStack
,其中包含多个HStacks
。当我尝试缩小2 HStacks
之间的间距时,会发生问题。
在以下代码段中,第一个Text
“标题”位于一个HStack
内的Spacer
内,后面是另一个内部有2个HStack
元素的Text
我想在矩形的正上方放置第一个Text
“标题”。没有像我现在这样的大空间。
有什么建议吗? 非常感谢你。
代码:
var body: some View {
VStack() {
HStack() {
Text("Title")
.font(Font.body)
.cornerRadius(ViewConstants.CORNERRADIUS)
.padding()
.foregroundColor(Colours.BLUE)
Spacer()
}
HStack(alignment: .firstTextBaseline) {
Spacer()
Text("SomeTextText")
.font(Font.bold(.body)())
.cornerRadius(ViewConstants.CORNERRADIUS)
.padding()
.foregroundColor(Color.gray)
.clipped()
Text("xx,00")
.font(Font.body)
.cornerRadius(ViewConstants.CORNERRADIUS)
.padding()
.foregroundColor(Color.gray)
Spacer()
} // HStack
.overlay(
RoundedRectangle(cornerRadius: ViewConstants.CORNERRADIUS)
.stroke(Colours.BLUE, lineWidth: 1)
) .padding(.init(top: 0, leading: 3, bottom: 0, trailing: 3))
...