skip to Main Content

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
    ...
   }
}

2

Answers


  1. 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)
     }
    
    Login or Signup to reply.
  2. Since navigationBarTitle(_:) is Deprecated. Use navigationTitle(_:) together with navigationBarTitleDisplayMode(_:) in iOS 14.0+

    NavigationView {
        VStack() {
           ...
        }
        .navigationTitle(Text("My Detail View"))
        .navigationBarTitleDisplayMode(.inline)
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search