【问题标题】:Change color of Navigation Button SwiftUI更改导航按钮 SwiftUI 的颜色
【发布时间】:2020-12-31 16:14:22
【问题描述】:

如何将导航“后退按钮”(它是自动创建的)的颜色更改为黑色, 以及 DisclosureGroup “Chevron” 的颜色为另一种颜色?

我尝试过 .buttonStyle(PlainButtonStyle()).foregroundColor(.black)

struct ContentView: View {

    var body: some View {
    
        NavigationView {
            NavigationLink(destination: DetailView()) {
        
                Text("Go to details ->")
                    .foregroundColor(.purple)
                    .underline()
            }
        }
    }
}


struct DetailView: View {
    @State private var isExpanded = false
    
    var body: some View {
        VStack {
            DisclosureGroup("All Details", isExpanded: $isExpanded) {
                
            }.buttonStyle(PlainButtonStyle())
            .foregroundColor(.black)

            Spacer()
        }
        .padding()
    }
}

【问题讨论】:

    标签: swift swiftui swiftui-navigationview


    【解决方案1】:

    在这种情况下使用.accentColor

            DisclosureGroup("All Details", isExpanded: $isExpanded) {
                
            }
            .accentColor(.black)
    

    添加

    struct ContentView: View {
    
        var body: some View {
        
            NavigationView {
                NavigationLink(destination: DetailView()) {
            
                    Text("Go to details ->")
                        .foregroundColor(.purple)
                        .underline()
                }
            }.accentColor(.black)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      相关资源
      最近更新 更多