为什么List会在SwiftUI中更改背景颜色?

时间:2019-08-03 00:58:27

标签: ios swift xcode uikit swiftui

到目前为止,基本上我所拥有的就是TabView内部的NavigationViews。 我当前正在处理的问题如下: 我通过初始化程序将颜色应用于TabView和NavigationView。现在,当我添加任何视图,例如Text()到HomeView的一切都很好,但是现在我想添加一个List,它以某种方式自动将背景色和所有内容更改为系统默认值(暗/亮)。 我有个将listRowBackground更改为特定颜色的想法,但是当将List向下拖动一点时,您会再次看到其后面的默认系统背景...

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()
    }
}

}

添加简单的Text()时的HomeView:

struct HomeView: View {

var body: some View {

    ZStack {
        Color.red.edgesIgnoringSafeArea(.all)

        Text("Test Text")
    }

    //Left out the NavigationBar icons
    ...

}

}

添加列表时的HomeView:

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

0 个答案:

没有答案