0

Whenever I put a List View inside a VStack, I get a background color and some unwanted padding. When List is not placed in a VStack, it looks as expected.

This image:

enter image description here

is what this this code looks like:

import SwiftUI

struct TodayView: View {
    
    init() {
        UITableViewHeaderFooterView.appearance().tintColor = UIColor.clear
    }
    
    @State private var selectedTab: Int = 1
    
    var body: some View {
        NavigationView {
            VStack(alignment: .leading) {
                Picker(selection: .constant(selectedTab), label: Text("Picker")) {
                    Text("Dairy").tag(1)
                    Text("Prospect").tag(2)
                    Text("Delivery").tag(2)
                }
                .pickerStyle(SegmentedPickerStyle())
                .padding(.top, 16)

               List {
                    Section(header: HStack {
                        Text("Appointments")
                            .font(.title)
                            .fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)
                            .padding()
                            .foregroundColor(.black)
                            
                            Spacer()
                    }
                    .background(Color.white)
                    .listRowInsets(EdgeInsets(
                            top: 0,
                            leading: 0,
                            bottom: 0,
                            trailing: 0))
                    ) {
                        NavigationLink(destination: Text("customer.name")) {
                           ExampleRow()

                        }
                    }
               
                }
            }
            .navigationBarHidden(true)

            Spacer()

        }
    }
    
    
}

struct ExampleRow: View {
    var body: some View {
        Text("Example Row")
    }
}

struct TodayView_Previews: PreviewProvider {
    static var previews: some View {
        TodayView()
    }
}

Removing VStack I see not padding. Can I have a List inside a VStack without the added bg and padding etc? "Diary" tab will be a List view while other may/not be.

Sylar
  • 11,422
  • 25
  • 93
  • 166

0 Answers0