Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present the old small title of UINavigationBar in SwiftUI NavigationView

Tags:

ios

swift

swiftui

Until now the default displayMode for UINavigationItem was small title and it changed in SwiftUI to be large by default.

Is it possible to use the old small title style?

like image 417
yogevbd Avatar asked Jun 05 '19 14:06

yogevbd


People also ask

How do I change the navigation 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. Text("Hello, SwiftUI!") <1> Because this is a customize of navigation bar title, a view needs to be embedded inside a NavigationView .

How do I show navigation bar in SwiftUI?

The navigation bar is on by default within a NavigationView. It can be hidden using navigationBarHidden(_:) . Note that the navigation bar can be unhidden by child views. navigationBarHidden(_:) is a preference value, and uses the value proposed by the deepest view in the hierarchy as its active value.

How do I customize my navigation bar in SwiftUI?

To change a navigation bar color in SwiftUI, you apply toolbarBackground modifier to the content view of NavigationStack . NavigationView is deprecated in iOS 16. toolbarBackground accepts two parameters. ShapeStyle : The style to display as the background of the bar.

What is a NavigationView in SwiftUI?

NavigationView is one of the most important components of a SwiftUI app, allowing us to push and pop screens with ease, presenting information in a clear, hierarchical way for users.


2 Answers

It is possible by passing displayMode: .inline attribute to navigationBarTitle()

NavigationView {   List {     Text("Text")   }.navigationBarTitle(Text("Title"), displayMode: .inline) } 
like image 180
yogevbd Avatar answered Sep 23 '22 18:09

yogevbd


SwiftUI 2 / iOS 14

Starting from iOS 14 the navigationBarTitle modifier is deprecated.

Instead we should "Use navigationTitle(_:) with navigationBarTitleDisplayMode(_:)":

List {     Text("Text") } .navigationTitle("Title") .navigationBarTitleDisplayMode(.inline) 
like image 35
pawello2222 Avatar answered Sep 23 '22 18:09

pawello2222