resu1
resu1

Reputation: 99

How to remove blank space on top of List in SwiftUI

SwiftUI reserves blank space on top of List for the title even though there is no title used.

How do i remove this space?

.navigationBarHidden() is not an option because the toolbar icons need to be shown.

enter image description here

Upvotes: 4

Views: 2680

Answers (2)

bdeviOS
bdeviOS

Reputation: 563

List {
    Text("Space1 ")
}
.listStyle(PlainListStyle())

try this...

Upvotes: 2

ScottM
ScottM

Reputation: 10404

That space is associated with the NavigationView that your List is in - each view within the "stack" of the navigation's displayable views can set its own title that would then get displayed in that spot.

If you're going to keep that space unused, you can mitigate by forcing the navigation title to be in inline mode. This is what you see when you scroll down a list and the big title shrinks and moves up into the toolbar space, between the leading and trailing toolbar items.

To do this, add the .navigationBarDisplayMode modifier to your list:

  // within a NavigationView context
  List {
     // ...
  }
  .navigationBarTitleDisplayMode(.inline)

Upvotes: 1

Related Questions