【发布时间】:2020-01-15 18:30:35
【问题描述】:
我尝试在 SwiftUI 中创建一个 iOS 视图,其中矩形作为 Stacks 周围的框架,但我无法减少 Text 和 HStack 框架之间的空间。
所以详细地说:我使用了一个VStack,里面有多个HStacks。当我尝试减少 2 HStacks 之间的空间时会出现问题。
在下面的代码 sn-p 中,第一个 Text“标题”在 HStack 中,Spacer 后跟另一个 HStack,其中有 2 个 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))
...
【问题讨论】:
-
你能附上截图吗?