Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the Navigation Bar Title Font with SwiftUI

Tags:

This is a SwiftUI question, not a UIKit one. :)

I'm trying to set a different font for the navigation bar title using SwiftUI. My suspicion is that this isn't supported yet. Here's what I've tried:

var body: some View {   NavigationView {     .navigationBarTitle(Text("Dashboard").font(.subheadline), displayMode: .large)   } } 

No matter what I do with the .font settings, it doesn't change the text. I've also tried setting a custom font and removing the displayMode property.

enter image description here

Has anyone been able to get this to work?

like image 966
Clifton Labrum Avatar asked Jun 14 '19 03:06

Clifton Labrum


People also ask

How do I customize the navigation bar title in SwiftUI?

To customize a navigation bar title view in SwiftUI, we simply set ToolbarItem of placement type . principal to a new . toolbar modifier.

How do I change the font in SwiftUI?

Hold the command key and click the text to bring up a pop-over menu. Choose Show SwiftUI Inspector and then you can edit the text/font properties.

How do I change the navigation title size in Swift?

Show activity on this post. let navigation = UINavigationBar. appearance() let navigationFont = UIFont(name: "Custom_Font_Name", size: 20) let navigationLargeFont = UIFont(name: "Custom_Font_Name", size: 34) //34 is Large Title size by default navigation.


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(Text("Dashboard").font(.subheadline), displayMode: .large)             //.navigationBarTitle (Text("Dashboard"), displayMode: .inline)         }     } } 

I hope this will help you. Thanks!!

like image 66
Anjali Kevadiya Avatar answered Sep 19 '22 19:09

Anjali Kevadiya