Fady E
Fady E

Reputation: 346

Gap in HStack between two views in SwiftUI

I am trying to have two views in an HStack using SwiftUI. However, I keep getting a gap between the two views. The problem occurs in both portrait and landscape layouts.

my code:

struct ContentView: View {

    var body: some View {

        GeometryReader { g in
            HStack {
                GeometryReader { g in
                    HStack {
                        VStack {
                            Text("View One")
                        }
                        .frame(width: g.size.width * 0.5, height: g.size.height, alignment: .center)
                        .background(Color.blue)

                        VStack {
                            Text("View Two")
                        }
                        .frame(width: g.size.width * 0.5, height: g.size.height, alignment: .center)
                        .background(Color.red)
                    }
                }
            }         
        }    
    }
}

The gap is between the View One and View Two

Upvotes: 8

Views: 2154

Answers (1)

Malik
Malik

Reputation: 3802

The spacing can be setup at the time of initialising

HStack(spacing: 0) {
    //Your code here
}

Upvotes: 18

Related Questions