在iPad上的列表上删除顶部和底线
我有一个用于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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
listRowSeparator修饰符应为内部 list
The listRowSeparator modifier should be inside list
Tested with Xcode 13.4 / iOS 15.5