1

I have a TextField and Text next in HStack Sections. There is a large empty space between them and I can not figure out how to remove it.

VStack{

    Section {
        HStack {
            TextField("Kohalik raha", text: $localMoney)
                .multilineTextAlignment(.center)
            Text("GEL")
                .multilineTextAlignment(.leading)
        }
    }
    Section {
        Text("\(money, specifier: "%.2f") EUR")
    }
    Section {
        HStack {
            TextField("Kurss", text: $rate )
                .multilineTextAlignment(.center)
            Text("Kurss")
                .multilineTextAlignment(.leading)
        }
    }
}

[Picture from app]

2 Answers 2

3

Make the textField have fixedSize to bring them near in center:

HStack {
    TextField("Kohalik raha", text: $localMoney)
        .background(Color.blue)
        .multilineTextAlignment(.center)
        .fixedSize()

    Text("GEL")
        .multilineTextAlignment(.leading)
        .background(Color.yellow)
}

Preview

I have added some colors to see better ;)

Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me with two buttons in an HStack. Thanks!
0

Add a Spacer() after the TextField and Text views.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.