0

Basically what I have so far are NavigationViews inside of a TabView. The problem that I am currently dealing with is the following: I applied colors to the TabView and the NavigationView via initializers. Now, when I add any View like e.g. Text() to the HomeView everything is perfectly fine, but now I would like to add a List which is somehow automatically changing the background color and everything to a system default one (dark / light). I had the idea to change the listRowBackground to a specific color, but when dragging the List down a bit, you would see the default system background behind it again...

TabView:

struct MainView: View {

init() {
    UITabBar.appearance().barTintColor = Theme.current.background
    UITabBar.appearance().unselectedItemTintColor = Theme.current.backgroundSecondary

    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().tintColor = Theme.current.backgroundPrimary
}

var body: some View {

    TabView {
        HomeNavigationView().tabItem {
            Image("HomeIcon")
        }.tag(0)

        //Left out the other tabs
        ...

    }.edgesIgnoringSafeArea(.top)
     .accentColor(Color(Theme.current.brand))
}

}

HomeNavigationView:

struct HomeNavigationView: View {

var body: some View {

    NavigationView {
        HomeView()
    }
}

}

HomeView when adding a simple Text():

struct HomeView: View {

var body: some View {

    ZStack {
        Color.red.edgesIgnoringSafeArea(.all)

        Text("Test Text")
    }

    //Left out the NavigationBar icons
    ...

}

}

HomeView when adding a List:

struct HomeView: View {

var body: some View {

    ZStack {
        Color.red.edgesIgnoringSafeArea(.all)

        List {
            Text("first row")
            Text("second row")
            Text("third row")
        }
    }

    //Left out the NavigationBar icons
    ...

}

}

Screenshot of when everything is ok ; Screenshot of the problem

  • Keep in mind that `SwiftUI` seems to be a "moving target" - betas 4 & 5 really messed things up for many. Have you tried using the `colorMultiply` modifier on your `List`? –  Aug 03 '19 at 02:06
  • @dfd Why should I consider multiplying a color value of the List? I just want to find out how to set a background instead of the white or black default ones that somehow appear, so that even if I drag the List up or down, there won‘t be any unwanted color visible. – Florian Leeser Aug 03 '19 at 02:17
  • You misunderstood. `colorMultiply` *is* the way to define a background color for your list. Search on it - here or wherever. (I certainly didn't make up the name, I'm only trying to help. Forgive me for sounding cynical - it's not you, it's the "moving target" that's SwiftUI. I decided today that until things are *much* more stable I won't be coding seriously in it. I expect this modifier name to change - like cornerRadius - in a future beta.) https://stackoverflow.com/questions/56517904/how-do-i-modify-the-background-color-of-a-list/56519943#56519943 –  Aug 03 '19 at 02:53
  • @dfd Well, when adding `colorMultiply(Color.clear)` on the List, everything works kind of great, since the background isn't black anymore. But now the Texts / Cells are also invisible. Furthermore when adding a real color into the brackets, the Lists background is black again and only the Texts are colored in that specific one. I tried to find a solution in the very last answer of the Post that you added in your comment, but it is not understandable to me. Any idea? – Florian Leeser Aug 03 '19 at 11:10

0 Answers0