1

to make it short: I want to have the same view of the list like in the first image i shared. But when I add a navigation bar item the list looks strange to me. It this a bug of the new version of Swift/XCode or needs something to be changed?

Code:

import SwiftUI
import CoreData

struct ContentView: View {

    var body: some View {
        
        NavigationView {
            List{
                Text("test1")
                Text("test2")
                Text("test3")

            }
            .navigationTitle("Test")
//            .navigationBarItems(leading:
//                Text("Test")
//            )
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Image 1

Image 2

Nick
  • 25
  • 4
  • You need to [edit] your question to include all relevant code as text, using proper code formatting - and not as a screenshot -, in the form of a [mcve] in order to make the question on-topic. – Dávid Pásztor Sep 21 '20 at 13:14
  • Does this answer your question? [SwiftUI iOS14 - NavigationView + List - Won't fill space](https://stackoverflow.com/questions/63938471/swiftui-ios14-navigationview-list-wont-fill-space) – pawello2222 Sep 21 '20 at 14:53

2 Answers2

1

Try using .navigationViewStyle as below:

struct ContentView: View {
   @State private var isFullScreen = false
   
   var body: some View {
       NavigationView {
        List{
            Text("One")
            Text("Two")
            
        }
        .navigationTitle("Testt")
        .navigationBarItems(leading: Text("Add"))
       }
       .navigationViewStyle(StackNavigationViewStyle())
   }
}

enter image description here

pawello2222
  • 46,897
  • 22
  • 145
  • 209
Anjali Aggarwal
  • 611
  • 4
  • 8
0

Hey! Give This A Try!

   var body: some View {
       NavigationView {
          List{
             Text("One")
             Text("Two")
        
    }
    .navigationTitle("Testt, displayMode: .inline)
    .navigationBarItems(leading: Text("Add"))
   }
  }
}
Dc7
  • 1,405
  • 1
  • 10
  • 16