Remove gap between lazyvgrids in vstack

Hello, I have the code below which creates a view. Unfortunately it puts a small gap between the two LazyVGrids that I would like to eliminate. Any suggestions would be appreciated. Below is my code. Chris

import SwiftUI

struct SecondView: View {

    

    var columns = [

        GridItem(.fixed(100), spacing: 0.1),

        GridItem(.fixed(100), spacing: 0.1),

        GridItem(.fixed(100), spacing: 0.1),

        GridItem(.fixed(100), spacing: 0.1),

        GridItem(.fixed(100), spacing: 0.1)

    ]

    let principalData: convertCSVtoArray

    

    var body: some View {

        let numArrays = principalData.cvsData.count

        let numElementsPerArray = principalData.cvsData[0].count

            

        VStack{

            Text("")

            Text("Historical Data")

                .font(.title)

                .padding(5)

            Divider()

            LazyVGrid(

                columns: columns,

                alignment: .center,

                spacing: 0)

            {

                ForEach(0..<1) {row in

                    ForEach(0..<numElementsPerArray) {col in

                        Rectangle()

                            .foregroundColor(.white)

                            .overlay (Text(principalData.cvsData[row][col]).bold())

                            .frame(height: 30)

                            .border(Color.gray, width: 2)

                    }

                }

            }

            ScrollView{

                LazyVGrid(

                    columns: columns,

                    alignment: .center,

                    spacing: 0)

                    {

                        ForEach(1..<numArrays) {row in

                            ForEach(0..<numElementsPerArray) {col in

                                Rectangle()

                                    .foregroundColor(.white)

                                    .overlay (Text(principalData.cvsData[row][col]))

                                    .frame(height: 30)

                                    .border(Color.gray, width: 0.5)

                            }

                        }

                    }

                ForEach(0..<30){index in

                    Text("")

                }

            }// end scrollview

        }

    }

}

We miss some code to be able to reproduce and test.

It's better to Paste as Paste and Match Style to avoid all the extra lines:

1. import SwiftUI
2. struct SecondView: View {
3.     
4.     var columns = [
5.         GridItem(.fixed(100), spacing: 0.1),
6.         GridItem(.fixed(100), spacing: 0.1),
7.         GridItem(.fixed(100), spacing: 0.1),
8.         GridItem(.fixed(100), spacing: 0.1),
9.         GridItem(.fixed(100), spacing: 0.1)
10.     ]
11.     let principalData: convertCSVtoArray
12.     
13.     var body: some View {
14.         let numArrays = principalData.cvsData.count
15.         let numElementsPerArray = principalData.cvsData[0].count
16.             
17.         VStack{
18.             Text("")
19.             Text("Historical Data")
20.                 .font(.title)
21.                 .padding(5)
22.             Divider()
23.             LazyVGrid(
24.                 columns: columns,
25.                 alignment: .center,
26.                 spacing: 0)
27.             {
28.                 ForEach(0..<1) {row in
29.                     ForEach(0..<numElementsPerArray) {col in
30.                         Rectangle()
31.                             .foregroundColor(.white)
32.                             .overlay (Text(principalData.cvsData[row][col]).bold())
33.                             .frame(height: 30)
34.                             .border(Color.gray, width: 2)
35.                     }
36.                 }
37.             }
38.             ScrollView{
39.                 LazyVGrid(
40.                     columns: columns,
41.                     alignment: .center,
42.                     spacing: 0)
43.                     {
44.                         ForEach(1..<numArrays) {row in
45.                             ForEach(0..<numElementsPerArray) {col in
46.                                 Rectangle()
47.                                     .foregroundColor(.white)
48.                                     .overlay (Text(principalData.cvsData[row][col]))
49.                                     .frame(height: 30)
50.                                     .border(Color.gray, width: 0.5)
51.                             }
52.                         }
53.                     }
54.                 ForEach(0..<30){index in
55.                     Text("")
56.                 }
57.             }   // end scrollview
58.         }
59.     }
60. }

a small gap between the two LazyVGrids

Do you mean those at lines 23 and 39 ? Is it due to the scrollView that adds some frame area ?

-> Could you post a screenshot to illustrate the problem ?

Yes, between those two lazyVgrids. I ended up adding negative padding right after the closing } of the first lazyVgrid and it removed the gap. .padding(.bottom, - 7.5) As far as a screen shot I know how to cut out a section with shift + command + 4. When I select the paper clip below and add image I select the associated png file from my desktop but I do no see it appear in this box. I clearly do not understand how to do it. Below is the section of code that includes the two lazyVgrids and the added padding. Thank you for giving me the heads up on paste and match style. It sure looks a lot cleaner.

Regards,

Chris

        LazyVGrid(
            columns: columns,
            alignment: .center,
            spacing: 0)
        {
            ForEach(0..<1) {row in
                ForEach(0..<numElementsPerArray) {col in
                    Rectangle()
                        .foregroundColor(.white)
                        .overlay (Text(principalData.csvData[row][col]).bold())
                        .frame(height: 30)
                        .border(Color.gray, width: 2)
                }
            }
        }.padding(.bottom, -7.5)
        ScrollView{
            LazyVGrid(
Remove gap between lazyvgrids in vstack
 
 
Q