在iPad上的列表上删除顶部和底线

发布于 2025-02-04 02:51:55 字数 1472 浏览 2 评论 0原文

我有一个用于iPad的应用程序,该应用程序使用导航列表,另一个用于显示项目的列表。即使没有项目,项目列表也总是显示顶部和底线。

我尝试了.listStyle(.plain).listrowseparator(.hidden) ,但没有任何帮助。 有人知道如何删除这些行吗?我在Apple的文档或这里找不到任何东西。

谢谢。

代码:

struct ContentView: View {
    @State var selection: Set<Int> = [0]
    
    var body: some View {
        NavigationView {
            List(selection: self.$selection) {
                NavigationLink(destination: ItemsList(wantStarred: 0)) {
                    Label("All Items", systemImage: "chart.bar.doc.horizontal").tag(0)
                }
                NavigationLink(destination: ItemsList(wantStarred: 1)) {
                    Label("Favorites", systemImage: "star.fill")
                }
                
            }
            .listStyle(SidebarListStyle())
            .frame(minWidth: 150, idealWidth: 150, maxHeight: .infinity)

            ItemsList(wantStarred: 0)
        }
    }
    
}


struct ItemsList: View {
    @State var wantStarred: Int
    
    var body: some View {
        List {
           //...
        }
        .listStyle(.plain)
        .listRowSeparator(.hidden)
        .overlay {
            if items.count == 0 {
                Text("Create a new item.").fontWeight(.light)
            }
        }

    }
}

I have an app for iPad that uses a navigation list, and another list to display items. The items list always displays a top and bottom lines, even when no items are there.

enter image description here

I have tried .listStyle(.plain) and .listRowSeparator(.hidden) but nothing helps.
Anyone has any idea how to remove those lines? I can't find anything on Apple's documentation or here at SO.

Thanks.

Code:

struct ContentView: View {
    @State var selection: Set<Int> = [0]
    
    var body: some View {
        NavigationView {
            List(selection: self.$selection) {
                NavigationLink(destination: ItemsList(wantStarred: 0)) {
                    Label("All Items", systemImage: "chart.bar.doc.horizontal").tag(0)
                }
                NavigationLink(destination: ItemsList(wantStarred: 1)) {
                    Label("Favorites", systemImage: "star.fill")
                }
                
            }
            .listStyle(SidebarListStyle())
            .frame(minWidth: 150, idealWidth: 150, maxHeight: .infinity)

            ItemsList(wantStarred: 0)
        }
    }
    
}


struct ItemsList: View {
    @State var wantStarred: Int
    
    var body: some View {
        List {
           //...
        }
        .listStyle(.plain)
        .listRowSeparator(.hidden)
        .overlay {
            if items.count == 0 {
                Text("Create a new item.").fontWeight(.light)
            }
        }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弄潮 2025-02-11 02:51:56

listRowSeparator修饰符应为内部 list

    List {
       Text("")
          .listRowSeparator(.hidden) // << like here !!
    }
    .listStyle(.plain)

The listRowSeparator modifier should be inside list

    List {
       Text("")
          .listRowSeparator(.hidden) // << like here !!
    }
    .listStyle(.plain)

demo

Tested with Xcode 13.4 / iOS 15.5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文