SwiftUI:如何更改 NavigationView 的色调(背景色)? [英] SwiftUI: How do you change the tint color (background color) of a NavigationView?

查看:40
本文介绍了SwiftUI:如何更改 NavigationView 的色调(背景色)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有列表的 NavigationView.如何更改 NavigationView 的颜色?

I have a NavigationView with a List in it. How do I change the color of the NavigationView?

推荐答案

没有直接的 api(yet) 可以做到这一点,但是您可以查看调试视图层次结构,您会看到它是一个简单的 UINavigationBar,所有旧的解决方案也可以在这里工作(但).

there is no direct api(yet) to do this, but you can look at the debug view hierarchy and you will see that it is a simple UINavigationBar and all of the old solutions would work here too(yet).

struct ContentView: View {

init(){
    UINavigationBar.appearance().backgroundColor = .white
    UINavigationBar.appearance().tintColor = .black
    UINavigationBar.appearance().barTintColor = .black
    UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.red]
    UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.red]
}
var body: some View {
    NavigationView {
        List {
            Text("1")
            Text("2")
            Text("3")
            Text("4")
        }.navigationBarTitle(Text("Title With Red Color"))
    }
}

}

这篇关于SwiftUI:如何更改 NavigationView 的色调(背景色)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆