Good day everyone,
I was trying to change the titleTextAttributes
of the UINavigationBar.appearance()
depending on the actual SystemColor (.dark, .light)
First of all I used an initializer to change the .foregroundColor
, everything works fine.
Additionally I want to automatically get it changed depending on light- or darkmode using colorScheme
.
This works fine on a button I added into the NavBar:
ToolbarItem(placement: .navigationBarTrailing) {
Button {
showingAddView.toggle()
} label: {
Label("Hinzufügen", systemImage: "plus.circle").foregroundColor(colorScheme == .dark ? Color.white : Color.black)
}
Now I have the problem not knowing how to solve that for UI Components...
I tried integrating colorScheme
like this:
init() {
let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.largeTitleTextAttributes = colorScheme == .dark ? [.foregroundColor: UIColor.white] : [.foregroundColor: UIColor.black]
navBarAppearance.titleTextAttributes = colorScheme == .dark ? [.foregroundColor: UIColor.white] : [.foregroundColor: UIColor.black]
}
But it didn't work
Does anybody know how to use colorScheme
or any other modifier to achieve this?
Thank you all in advance!
Greetings Marcel