0

I would like to change my background color, but I am using NavigationView and List. That's why the ZStack method doesn't work for me.

This is my Code:

NavigationView {
    List {
        Text("Some Text")
    }

    .navigationBarTitle("Test")
}
Mattis Schulte
  • 639
  • 1
  • 10
  • 18

3 Answers3

1

You can use .listRowBackground inside the List.

  ZStack{
        Color.blue
   NavigationView {
    ZStack{
        Color.red
       List {
        ZStack{
            Color.green
            Text("Some Text").background(Color.green).opacity(0.5)

        }.listRowBackground(Color.red)
        }
    }
       .navigationBarTitle("Test")
   }.padding()

    }
E.Coms
  • 11,065
  • 2
  • 23
  • 35
  • It doesn't work really well. The navigation bar is fixed. So the larger lists scroll through the Navigation bar which looks very strange. But thanks for the answer anyway – Mattis Schulte Oct 31 '19 at 15:48
  • You can use .inline style to make the navigation bar much smaller. In principle, list can be configured with listStyle if you know how to customize it. – E.Coms Oct 31 '19 at 16:25
  • 1
    You may need to check this post: https://stackoverflow.com/questions/57128547/swiftui-list-color-background – E.Coms Oct 31 '19 at 17:39
0
NavigationView {
    List {
         Text("Some Text")
    }
    .navigationBarTitle("Test")
}.colorMultiply(Color.green)
0

Finally I have found an answer to my problem:

init() {
    UITableView.appearance().backgroundColor = UIColor(named: "CustomBackgroundColor")
    UITableViewCell.appearance().backgroundColor = UIColor(named: "CustomBackgroundColor")
    UITableView.appearance().tableFooterView = UIView()
}

var body: some View {
    NavigationView {
        List {
            Text("Hello")
        }

        .navigationBarTitle("Test")
    }
}
Mattis Schulte
  • 639
  • 1
  • 10
  • 18