2

I'm trying to get the navigation title vertically aligned with the back button in a NavigationDetail view in SwiftUI. Here's what this looks like currently:

enter image description here

Below's my code for adding the Navigation Bar title to the view. How do I get it vertically aligned with the Back button?

 var body: some View {
        Text("My Detail View")
            .navigationBarTitleDisplayMode(.inline)

        VStack {
            List {
                ForEach(0..<layerSettings.count, id: \.self) { each in
    ...
   }
}
narner
  • 2,908
  • 3
  • 26
  • 63

2 Answers2

4

If you need to draw "My Detail View" on the same line that the Back button, try to do like this:

 NavigationView {
    VStack() {
       ...
    }
    .navigationBarTitle(Text("My Detail View"),
                        displayMode: .inline)
 }
stosha
  • 2,108
  • 2
  • 27
  • 29
4

Since navigationBarTitle(_:) is Deprecated. Use navigationTitle(_:) together with navigationBarTitleDisplayMode(_:) in iOS 14.0+

NavigationView {
    VStack() {
       ...
    }
    .navigationTitle(Text("My Detail View"))
    .navigationBarTitleDisplayMode(.inline)
 }
YodagamaHeshan
  • 4,996
  • 2
  • 26
  • 36