英文:
Hide list separator/divider in NavigationStack
问题
I have a problem with the sticky header in my view, when I scroll up I don't want that separator line on the video to be.
Just want to remove this separator, all list modifiers are not working for me.
My View code:
import SwiftUI
struct CalendarView: View {
let dayLetters = ["S", "M", "T", "W", "T", "F", "S"]
var body: some View {
NavigationStack {
List {
Section {
RootView()
} header: {
HStack {
ForEach(0..<dayLetters.count, id: \.self) { index in
Text(dayLetters[index])
.frame(maxWidth: .infinity)
.foregroundColor(.white)
}
}
}
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)
}
.navigationTitle("Calendar")
.listStyle(.plain)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Today") {
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Label("Transform Calendar", systemImage: "ellipsis")
.foregroundColor(.accentColor)
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
} label: {
Label("Add", systemImage: "plus")
}
}
}
}
}
}
英文:
I have a problem with the sticky header in my view, when I scroll up I don't want that separator line on the video to be.
Just want to remove this separator, all list modifiers are not working for me.
My View code:
import SwiftUI
struct CalendarView: View {
let dayLetters = ["S", "M", "T", "W", "T", "F", "S"]
var body: some View {
NavigationStack {
List {
Section {
RootView()
} header: {
HStack {
ForEach(0..<dayLetters.count, id: \.self) { index in
Text(dayLetters[index])
.frame(maxWidth: .infinity)
.foregroundColor(.white)
}
}
}
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)
}
.navigationTitle("Calendar")
.listStyle(.plain)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Today") {
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Label("Transform Calendar", systemImage: "ellipsis")
.foregroundColor(.accentColor)
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
} label: {
Label("Add", systemImage: "plus")
}
}
}
}
}
}
答案1
得分: 1
尝试将List
替换为VStack
。如果需要滚动,请考虑在ScrollView
内嵌套LazyVStack
。
英文:
Do you have to be using List
here? Try replacing List
with a VStack
. If you need scrolling, consider using a LazyVStack
nested within a ScrollView
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论