Swift development tips and experiences by Tommi Kivimäki

Browse all notes

Set navigation bar title text color in SwiftUI

SwiftUI cannot change the navigation bar title color with a modifier at the moment. It was a surprise, since it's such a basic thing to do. I had to change the color in the init() by using the appearance API.

        
          init() {
            let navBarAppearance = UINavigationBar.appearance()
            navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
            navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
          }