简体   繁体   中英

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.

在此处输入图像描述

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)
List {
    Text("Space1 ")
}
.listStyle(PlainListStyle())

try this...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM