0

I have two navigation views. The parent is white labeled and the child is black labeled. When I revisit the parent view from the child view the child modifier is still applied. i.e the labels are white instead of black. I understand that applying View modifier to a navigation view changes all navigations views.

So my question is how do I toggle between two text colors in navigation views without using view modifier?

ParentNavigationView {
    ChildNavigationView {
          .whiteTextColorModifier()
    }
}
.blackTextColorModifier()
tintin
  • 107
  • 2
  • 6

1 Answers1

0

Use this code in the init(){} of SwiftUI View.

init() {
        UINavigationBar.appearance().titleTextAttributes = [ NSAttributedString.Key.foregroundColor :  UIColor.white] // Use your own color
        UINavigationBar.appearance().barTintColor = UIColor.black
        UINavigationBar.appearance().backgroundColor = UIColor.whatever
UINavigationBar.appearance().tintColor = .white
        UINavigationBar.appearance().isOpaque = true
       }
Shahriar Nasim Nafi
  • 1,160
  • 15
  • 19
  • Still doesn't change back on child dismiss. Maybe should add I'm presenting the child view as a sheet. It's not in a different group view – tintin Jun 25 '21 at 23:19