navigation bar title swiftui code example

Example 1: swift navigation bar title color

// Place this in your didFinishLaunchingWithOptions method in the AppDelegate
let attrs = [
  NSAttributedString.Key.foregroundColor: UIColor.white
]

UINavigationBar.appearance().titleTextAttributes = attrs

Example 2: swift change navigation bar title

// Place this in your didFinishLaunchingWithOptions method in the AppDelegate
let attrs = [
  NSAttributedString.Key.foregroundColor: UIColor.white, // changes color
  NSAttributedString.Key.font: UIFont(name: "Futura-Bold", size: 17)! // changes font
]

UINavigationBar.appearance().titleTextAttributes = attrs

Example 3: swift show title on navigation bar programmatically

override func viewDidLoad() {
     super.viewDidLoad()
     self.title = "Your title over here"
}

Example 4: navigation bar title ios 13 siwftui

import SwiftUI

// 1.
struct People: Identifiable{
    var id  = UUID()
    var name = String()
}

struct ContentView: View {
    // 2.
    let people: [People] = [
        People(name: "Bill"),
        People(name: "Jacob"),
        People(name: "Olivia")]
    
    var body: some View {
        NavigationView {
            // 3.
            List(people) { listedPeople in
                NavigationLink(destination: DetailView(name: listedPeople.name)) {
                    VStack(alignment: .leading){
                        Text(listedPeople.name)
                    }
                }
            }
            // 4.
            .navigationBarItems(leading:
            HStack {
                Button(action: {}) {
                    Image(systemName: "minus.square.fill")
                        .font(.largeTitle)
                }.foregroundColor(.pink)
            }, trailing:
            HStack {
                Button(action: {}) {
                    Image(systemName: "plus.square.fill")
                        .font(.largeTitle)
                }.foregroundColor(.blue)
            })
                // 5.
                .navigationBarTitle(Text("Names"))
        }
    }
}
// 6.
struct DetailView: View {
    var name: String
    
    var body: some View {
        Text("current name is: \(name) ")
         // 7.
        .navigationBarTitle(Text("Current Name"), displayMode: .inline)
    }
}