Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How change .navigationBarTitle font in SwiftUI?

I'm using SwiftUI with Xcode 11 and I want to change NavigationBarTitle font with these lines of codes:

.navigationBarTitle (Text("Navigation Bar Title"), displayMode: .inline)
    .font(.subheadline)

but nothing happened. any suggestion or comment?

like image 356
Sajjad Avatar asked Dec 07 '25 05:12

Sajjad


1 Answers

In SwiftUI, at this point we can not change the navigationBarTitle font directly, but you can change navigationBar appearance like this,

struct YourView: View {
    init() {
        //Use this if NavigationBarTitle is with Large Font
        //UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont(name: "Georgia-Bold", size: 20)!]

        //Use this if NavigationBarTitle is with displayMode = .inline
        UINavigationBar.appearance().titleTextAttributes = [.font : UIFont(name: "Georgia-Bold", size: 20)!]
    }
    var body: some View {
        NavigationView {
            Text("Hello World!")
            //.navigationBarTitle("TEST")
            .navigationBarTitle (Text("TEST"), displayMode: .inline)
        }
    }
}

I hope it will help you. Thanks!!

like image 81
Anjali Kevadiya Avatar answered Dec 09 '25 02:12

Anjali Kevadiya