SwiftUi:如何减少框架和文本之间的空间?

问题描述 投票:0回答:1

我已经尝试在SwiftUI中为iOS创建一个View,使用矩形作为围绕Stacks的框架,但是我无法缩小TextHStack框架之间的空间。

详细说明:我使用的VStack中包含多个HStacks。当我尝试减小2 HStacks之间的间隔时,会出现问题。

在下面的代码片段中,第一个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))
...
ios stack swiftui frame
1个回答
0
投票

我想在矩形正上方放置第一个文本“标题”。没有像我目前这样的大空间。

我认为是预期的

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9TeEJEay5wbmcifQ==” alt =“在此处输入图像描述”>

Text("Title")
    .font(Font.body)
    .cornerRadius(ViewConstants.CORNERRADIUS)
    .padding(.horizontal) // << only horizontal padding
© www.soinside.com 2019 - 2024. All rights reserved.