Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
742 views
in Technique[技术] by (71.8m points)

swift - Change color of Navigation Button SwiftUI

How to change the color of Navigation "Back Button" (it's created automatically) to black, and the color of DisclosureGroup "Chevron" to another color?

enter image description here

I've tried to do .buttonStyle(PlainButtonStyle()) and .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()
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use .accentColor for such cases

demo

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

ADDED

struct ContentView: View {

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share

1.2m questions

2.1m answers

5 comments

56.5k users

...