[ 1 SOLUTION FOUND! ] Thanks to George's comment I was able to find a solution https://stackoverflow.com/a/70353393/882987 but if somebody has any other solution feel free to write it:)
I am having some issues with setting custom navigation bar tint color in SwiftUI for "pushed" views.
Code is something like this, having a stack of items and tapping on each of them we show/push some detail view:
NavigationView {
ScrollView {
LazyVStack(alignment: .leading) {
ForEach(items) { item in
NavigationLink(destination: DetailItemView(item))) {
ListItemView(item)
}
}
}
}
}
And I would like to have different navigation bar tint color for each view that gets pushed.
Is there a way to achieve that?
Thanks to George's comments I was able to find a solution, using basic Binding .
In the view A I added:
@State private var navColor = Color.primary
and I added the modifier :
NavigationView {
...
}
.accentColor(navColor)
And in view B I added:
@Binding var navColor: Color
So I can change the navColor property to anything I want in view B and it will update the accentColor (and with that the navigation bar tint color)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.