1

I'm currently developing an application using SwiftUI.

When I use 2 HStacks which have Images in a Vstack, the VStack makes a space between 2 HStacks like the photo below: enter image description here

Then How can I remove that space?

I am confused about this problem because if I exchange Images in HStacks to Texts, that space disappears... enter image description here

How can I remove that space when I use Images in HStacks?


Here is the code:

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack{
            HStack{
                Image(systemName: "circle")
//                Text("test")
            } .frame(maxWidth: .infinity, maxHeight: .infinity)
                .background(Color.yellow)
            HStack{
                Image(systemName: "circle")
//                Text("test")
            } .frame(maxWidth: .infinity, maxHeight: .infinity)
                .background(Color.blue)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Xcode: Version 11.7

Swift: Swift 5


Tio
  • 944
  • 3
  • 15
  • 35
  • Does this answer your question? [How to adjust spacing between HStack elements in swiftUI?](https://stackoverflow.com/questions/56506357/how-to-adjust-spacing-between-hstack-elements-in-swiftui) – pawello2222 Sep 04 '20 at 08:54
  • @pawello2222, I refer to the page you introduced but I couldn't solve this situation...I changed my code to like this `HStack(spacing: 0){ contents }` but it doesn't work... – Tio Sep 04 '20 at 09:01
  • 1
    Use `VStack(spacing: 0)` You want to remove spacing in the VStack (vertical), not in the HStack (horizontal). – pawello2222 Sep 04 '20 at 09:03
  • @pawello2222, thank you for your help, now the code works as I expected! – Tio Sep 04 '20 at 09:05

0 Answers0