简体   繁体   English

(SwiftUI) NavigationLink 不是全屏宽度

[英](SwiftUI) NavigationLink is not full width of screen

When the NavigationView is in the root, and NavigationLink is in the subView, like the code below, the label of navigation link cannot take the full width of screen.NavigationView在root中, NavigationLink在subView中时,如下代码,导航链接的标签不能占据屏幕的全部宽度。

If I move the NavigationView to the subView( ListView ), the label will be full width, but I cannot navigate to a full screen destination.如果我将NavigationView移动到 subView( ListView ),标签将是全宽的,但我无法导航到全屏目标。

Can anyone help?任何人都可以帮忙吗? the requirement is 1. full width of navigation link label and 2. navigate to a full screen view.要求是 1. 导航链接标签的全宽和 2. 导航到全屏视图。 Or should I use fullScreenCover to do this?或者我应该使用 fullScreenCover 来做到这一点?

    struct ContentView: View {
        var body: some View {
            NavigationView {
                VStack {
                    ListView()
                    Text("Tabs here")
                }
            }
        }
    }
    
    struct ListView: View {
        var body: some View {
            List {
                NavigationLink(
                    destination: Text("detail for item1"),
                    label: {
                        Text("item1")
                    }
                )
                NavigationLink(
                    destination: Text("detail for item2"),
                    label: {
                        Text("item2")
                    }
                )
            }
        }
    }

在此处输入图片说明

Using PlainListStyle() will cause the rows to take up the entire width:使用PlainListStyle()将导致行占据整个宽度:

List {
  NavigationLink(
      destination: Text("detail for item1"),
      label: {
          Text("item1")
      }
  )
  NavigationLink(
      destination: Text("detail for item2"),
      label: {
          Text("item2")
      }
  )
}.listStyle(PlainListStyle())

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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